setenv/unsetenv's known memory leak
Peter Jeremy
PeterJeremy at optushome.com.au
Wed Feb 23 08:51:03 GMT 2005
On Tue, 2005-Feb-22 22:01:12 -0600, Seán C. Farley wrote:
>The latest PR on this (two PR's mentioned in it are closed):
>http://www.freebsd.org/cgi/query-pr.cgi?pr=misc/19406
...
>Here is a test program along with a patch to stop the leak:
>http://www.farley.org/freebsd/tmp/setenv.tar.bz2
The diff is unnecessarily difficult to read because you've included both
whitespace and functional changes.
Your fix won't work because it assumes that all environment strings are
malloc()'d. The environment that was passed to a program during exec()
is static so if you tried to update (eg) $PATH, things blow up. If
I change "TESTVAR" to "PATH" and run the program, I get:
$ ./testenv
testenv in realloc(): warning: malloc() has never been called
As discussed in conjunction with the previous PRs, there is no easy
solution (otherwise it would have been fixed 7 years ago). Most other
OSs side-step the problem by requiring the caller to ensure that the
strings passed as arguments remain in scope.
--
Peter Jeremy
More information about the freebsd-hackers
mailing list