bug in putenv()!

marty Leisner.Henr at xerox.com
Thu Feb 23 04:46:19 AEST 1989


According to Christopher J. Calabrese
>> If putenv always malloc'd space, it would start eating up
some serious memory in something like the shell, where you might
change the value of an environment variable several hundred
times in a particularly large script (please don't ask for examples,
you get the general idea :-)

I don't agree -- putenv could detect whether an equivalent environment
string already exists.  If putenv always does a malloc/strcpy, whenever a
string is overwritten it could free  or realloc the storage.

I had a version which works sorta this way on Ms/Dos (actually the whole
environment array was one malloced block ).

A version of putenv on a masscomp I'm looking at right now appears to work
the same way (it uses realloc on successive calls to putenv after the first
malloc [hmmm -- maybe someone else had the same idea ;-) ]).

I find having to allocate static storage for putenv to be kinda strange --
I guess it's another portability bugaboo.

marty
ARPA:	leisner.henr at xerox.com
GV:  leisner.henr
NS:  martin leisner:wbst139:xerox
UUCP:  hplabs!arisia!leisner



More information about the Comp.unix.wizards mailing list