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

Relevant Pages

  • [PATCH 0/6] epoll fixes and cleanups
    ... This bug has the potential to confuse ... The test program uses a thread blocked in readto keep the struct ... Patches #2 and #3 fix some minor issues; ... I would like to have patch #1 included in 2.6.29 and -stable. ...
  • Re: [PATCH] mremap NULL pointer dereference fix
    ... To trigger the bug, I have to run my test program in a "while true;" ... > extra goto in the generated assembly unless the compiler is clever enough ... send the line "unsubscribe linux-kernel" in ...
  • Re: Detecting stack corruption
    ... > a module loader to it. ... but the test program I wrote ... Valgrind is very good at finding things like ... Erik de Castro Lopo ...
  • weird error message after gnat installation
    ... i made this simple test program ... procedure test is begin null; end; ... | Use a subject line meaningful to you and us to track the bug. ... i retried the download and the install but no change. ...
  • [PATCH] fix for futex_wait signal stack corruption
    ... David Holmes found a bug in the RT patch with respect to ... After trying his test program on the latest git ... struct restart_block *restart; ...