Xref: utzoo comp.unix.microport:2870 comp.unix.wizards:14801 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!rutgers!gatech!ulysses!cjc From: cjc@ulysses.homer.nj.att.com (Chris Calabrese[mav]) Newsgroups: comp.unix.microport,comp.unix.wizards Subject: Re: bug in putenv()! Summary: putenv allocating space Keywords: bug putenv Message-ID: <11247@ulysses.homer.nj.att.com> Date: 21 Feb 89 21:33:13 GMT References: <204@tree.UUCP> <1046@auspex.UUCP> <233@tree.UUCP> Organization: AT&T Bell Laboratories, Murray Hill Lines: 37 In article <233@tree.UUCP>, asmodeus@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@ulysses.att.com Obligatory Quote: ``Now, where DID I put that bagel?''