Date: Wed, 23 Feb 2005 19:50:53 +1100 From: Peter Jeremy <PeterJeremy@optushome.com.au> To: =?iso-8859-1?Q?Se=E1n_C=2E?= Farley <sean-freebsd@farley.org> Cc: freebsd-hackers@freebsd.org Subject: Re: setenv/unsetenv's known memory leak Message-ID: <20050223085053.GA85422@cirb503493.alcatel.com.au> In-Reply-To: <20050222173013.B26342@thor.farley.org> References: <20050222173013.B26342@thor.farley.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050223085053.GA85422>