[Patch] Make getenv() functional before the environment is initialized

Pierre A. Humblet pierre@phumblet.no-ip.org
Fri Apr 21 20:33:00 GMT 2006

----- Original Message ----- 
From: "Christopher Faylor" <cgf-no-personal-reply-please@cygwin.com>
To: <cygwin-patches@cygwin.com>
Sent: Friday, April 21, 2006 4:12 PM
Subject: Re: [Patch] Make getenv() functional before the environment is 

>>But doesn't the program then have a pointer to memory that has been freed?
>>That pointer can also be accessed after forks.
> Isn't that always a possibility?  You can't rely on the persistence of
> the stuff returned from getenv().

That's not my reading of 

"The string pointed to may be overwritten by a subsequent call to getenv(),
 but shall not be overwritten by a call to any other function in this volume of 
IEEE Std 1003.1-2001."

Athough Posix allows the string to be overwritten, indicating that persistence 
is implied,
it does not allow the pointer to become invalid.

See also
which says that the environment semantics make it inherently leaky.
That's why I didn't hesitate calling cmalloc


More information about the Cygwin-patches mailing list