[PATCH v2 1/2] [libXau] XauGetFileName: added a thread-safe variant of XauFileName

Mikhail Gusarov dottedmag at dottedmag.net
Thu Mar 31 05:18:13 PDT 2011


Twas brillig at 13:13:23 31.03.2011 UTC+01 when mark.marshall at csr.com
did gyre and gimble:

 >> +static const char *
 >> +xau_getenv(const char *name)
 >> +{
 >> +    size_t  len        = 64;
 >> +    char   *buffer = malloc (len);
 >> +    int            rc = 0;
 >> +
 >> +    while (buffer
 >> +        &&  (rc = getenv_r (name, buffer, len)) == -1
 >> +        &&  errno == ERANGE) {
 >> +        len *= 2;
 >> +        free (buffer);
 >> +        buffer = malloc (len);
 >> +    }
 >> +    return rc == 0 ? buffer : NULL;
 >> +}
 MM> There's a (very unlikely) memory leak here.
 MM> (getenv_r() == -1 and errno != ERANGE)

Actually quite likely:

[ENOENT] The variable name was not found in the environment.

-- 
  http://fossarchy.blogspot.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20110331/284a33e5/attachment.pgp>


More information about the xorg-devel mailing list