bug in putenv()!

Chris Calabrese[mav] cjc at ulysses.homer.nj.att.com
Wed Feb 22 07:33:13 AEST 1989


In article <233 at tree.UUCP>, asmodeus at tree.UUCP (Jonathan Ballard) writes:
> From what you people have been saying is that I can't pass in a automatic
> varible because putenv uses that space, right?
> This seems to be a dumb way to go.  Why doesn't putenv just alloc a new
> spot for the enviroment varible to go? (Like mine does.)
> But if I do understand this right - I have to make several global or
> static varible just to handle space for the enviroment.  This to me 
> seems to make things clutter up.

No, just malloc them before passing them to putenv, as you
are doing now.

It seems to me that putenv is a useful function which
operates on a fairly low level on a very simple data structure
(array of pointers).  It also works.  The user, however,
may opt to develop an interface to putenv which will optimize
for speed, memory usage, etc.

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 :-).
It could free the old space, however, there's
no way of telling if it was created by malloc in the first place,
to it would either have to maintain a list of what's freeable,
or malloc new space for the whole environment at the start of the
program.

Perhaps the real answer is a better data structure for the
environment, but I thing UNIX (all flavors) is pretty much stuck
with the current one.
-- 
Name:			Christopher J. Calabrese
Brain loaned to:	AT&T Bell Laboratories, Murray Hill, NJ
att!ulysses!cjc		cjc at ulysses.att.com
Obligatory Quote:	``Now, where DID I put that bagel?''



More information about the Comp.unix.wizards mailing list