Yitzchak Scott-Thoennes <sthoenna@efn.org> writes: >In article <19991118210401.A16532@monk.mps.ohio-state.edu>, >Ilya Zakharevich <ilya@math.ohio-state.edu> 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 : DESCRIPTION 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"; putenv(myvar); 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 <nik@tiuk.ti.com> Via, but not speaking for: Texas Instruments Ltd.Thread Previous | Thread Next