Using environment variables without leaking memory?

Dave Dodge dododge at dododge.net
Wed Oct 25 15:20:24 PDT 2006


On Tue, Oct 24, 2006 at 03:51:35PM -0400, Rob Landley wrote:
> because what if somebody did a getenv() and kept the pointer around after 
> doing an unsetenv()?

Then they're broken by definition.  POSIX/SUS explicitly says that the
getenv results can be damaged by getenv, setenv, or unsetenv (but by
no other library function).

If you're willing to make broken programs break, you can probably
implement the environment stuff without too much pain.  putenv is
perhaps the worst of it, though somewhat ironically the rationale for
keeping it in the Standard was that it's the only guaranteed way to
avoid memory leaks.

                                                  -Dave Dodge


More information about the uClibc mailing list