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

Mark Marshall mark.marshall at csr.com
Thu Mar 31 05:13:23 PDT 2011


On 30/03/2011 09:53, Erkki Seppälä wrote:
> +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;
> +}
There's a (very unlikely) memory leak here.
(getenv_r() == -1 and errno != ERANGE)

MM



More information about the xorg-devel mailing list