This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add get_current_dir_name(3)


On 01/01/2012 12:13 AM, Yaakov (Cygwin/X) wrote:
>> > You have to check st_dev here too don't you?
> Of course.  Revised patch for winsup/cygwin attached.
> 

> +extern "C" char *
> +get_current_dir_name (void)
> +{
> +  char *pwd = getenv ("PWD");
> +  char *cwd = getcwd (NULL, 0);
> +
> +  if (pwd)
> +    {
> +      struct __stat64 pwdbuf, cwdbuf;
> +      stat64 (pwd, &pwdbuf);
> +      stat64 (cwd, &cwdbuf);
> +      if ((pwdbuf.st_dev == cwdbuf.st_dev) && (pwdbuf.st_ino == cwdbuf.st_ino))
> +        {
> +          cwd = (char *) malloc (strlen (pwd) + 1);

Memory leak.  You need to free(cwd) before reassigning it.  And why are
you using malloc(strlen())/strcpy(), when you could just use strdup()?

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]