Making getenv more multi-threading--robust?
Stephan Bergmann
sbergman@redhat.com
Wed Sep 19 08:43:00 GMT 2012
On 09/14/2012 12:09 PM, Florian Weimer wrote:
> On 09/13/2012 12:56 PM, Stephan Bergmann wrote:
>> I stumbled over this when running the LibreOffice test suite and getting
>> sporadic crashes in getenv(3). It turns out that LibreOffice contains
>> many places that call getenv (mostly to check whether to enable one
>> tweak or another) at arbitrary times and from arbitrary threads, and
>> apparently also contains the odd call to setenv etc. to modify the
>> environment.
>
> FWIW, the C11 standard appears to contain a getenv_s call (I haven't got
> a copy), but this seems to deal with a different issue: Apparently,
> there are implementations out there which free memory on putenv/setenv,
> invalidating pointers previously returned by getenv.
>
> But this is suggests to me that everyone else manages getenv/environ
> slightly differently from us, so we can't except much guidance from the
> standards. 8-(
Note that the C Standard only covers getenv but no functionality to
modify the environment, so the issue at hand is not relevant there.
Stephan
More information about the Libc-alpha
mailing list