develooper Front page | perl.perl5.porters | Postings from November 1999

Re: [ID 19991116.002] perl5.005_02: my_setenv() and Term::ReadLine::Gnu

Thread Previous | Thread Next
Nick Ing-Simmons
November 19, 1999 01:14
Re: [ID 19991116.002] perl5.005_02: my_setenv() and Term::ReadLine::Gnu
Message ID:
Yitzchak Scott-Thoennes <> writes:
>In article <>,
>Ilya Zakharevich <> wrote:
>>On Fri, Nov 19, 1999 at 01:37:35AM +0100, Joerg Schumacher wrote:
>>I do not believe this.  At least the documentation I see states that
>>putenv() will malloc() environ if it needs to modify it.  Thus with
>>usemymalloc=n the test is OK as is.
>Single UNIX V2 seems to say otherwise.  In particular it states that
>if you call putenv(string) and then later change string, the
>environment will be changed.  (Yuck) It also warns against passing an
>pointer to an auto since it could go out of scope leaving a bad
>pointer in the environment.

Solaris7 still says that : 

     The putenv() function makes the  value  of  the  environment
     variable  name  equal to value by altering an existing vari-
     able or creating a new  one.  In  either  case,  the  string
     pointed  to  by  string  becomes part of the environment, so
     altering the string will change the environment.

Thus one must malloc the string.
However it is far from clear that the incoming environ has each string 
malloc'ed individually. Nor can one be sure that some XS module has 
not done : 

static char *myvar = "HOME=/some/place";

Thus as far as I can see unless we keep a hash of "things we malloc'ed"
and check for match we should not free() anything in environ.

Nick Ing-Simmons <>
Via, but not speaking for: Texas Instruments Ltd.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About