Re: Segfault in getenv

From: Måns Rullgård (
Date: 03/17/05

Date: Thu, 17 Mar 2005 20:19:08 +0100

Bruno Barberi Gnecco <> writes:

> Måns Rullgård wrote:
> Hi Måns!
>>> I'm developing a threaded application that is segfaulting, for
>>>no apparent reason, at getenv. Here's a typical stack trace:


>>> getenv is never called directly from the program. The bug is
>>>easily reproduceable, which makes me doubt that there's a racing
>>>condition. Any ideas of what might be going on? Is there some known
>>>problem of reentrancy in getenv? (BTW, gethostname_r does not work
>>>either, with the same bug and stack trace of gethostname).
>> Can you produce the same error in a short test program? If yes, post
>> it, otherwise get valgrind up and running.
> I can post the code, but it would require downloading the
> library. It's on the CVS, actually (, file
> test/general/autotestgeneral)... It is a short test program.
> Valgrind did not help at all. I'm wondering if it is not
> a libc bug...

If you suspect a libc bug, try to isolate a simple test case that
triggers it. More often than not, you'll end up finding the bug in
your own code instead.

Måns Rullgård