[PATCH v2 1/2] [libXau] XauGetFileName: added a thread-safe variant of XauFileName
Mark Kettenis
mark.kettenis at xs4all.nl
Thu Mar 31 05:57:01 PDT 2011
> From: Mikhail Gusarov <dottedmag at dottedmag.net>
> Date: Thu, 31 Mar 2011 14:18:13 +0200
>
> 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 =3D 64;
> >> + char *buffer =3D malloc (len);
> >> + int rc =3D 0;
> >> +
> >> + while (buffer
> >> + && (rc =3D getenv_r (name, buffer, len)) =3D=3D -1
> >> + && errno =3D=3D ERANGE) {
> >> + len *=3D 2;
> >> + free (buffer);
> >> + buffer =3D malloc (len);
> >> + }
> >> + return rc =3D=3D 0 ? buffer : NULL;
> >> +}
> MM> There's a (very unlikely) memory leak here.
> MM> (getenv_r() =3D=3D -1 and errno !=3D ERANGE)
>
> Actually quite likely:
>
> [ENOENT] The variable name was not found in the environment.
It's probably best to drop the bit of the patch that tries to use
getenv_r(3) for now. The standard getenv(3) on NetBSD provides
essentially the same amount of thread-safeness as the Solaris one
(safe with respect to another thread modifying the list of environment
variables, not safe with respect to another thread modifying the
environment variable you're looking at).
More information about the xorg-devel
mailing list