[PATCH] Add get_current_dir_name(3)

Eric Blake eblake@redhat.com
Mon Jan 2 12:56:00 GMT 2012


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20120102/d3731f95/attachment.sig>


More information about the Cygwin-patches mailing list