From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 23 08:51:03 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BB2F616A4CE for ; Wed, 23 Feb 2005 08:51:03 +0000 (GMT) Received: from mail09.syd.optusnet.com.au (mail09.syd.optusnet.com.au [211.29.132.190]) by mx1.FreeBSD.org (Postfix) with ESMTP id E477743D48 for ; Wed, 23 Feb 2005 08:51:02 +0000 (GMT) (envelope-from PeterJeremy@optushome.com.au) Received: from cirb503493.alcatel.com.au (c211-30-75-229.belrs2.nsw.optusnet.com.au [211.30.75.229]) j1N8osif007752 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO); Wed, 23 Feb 2005 19:50:56 +1100 Received: from cirb503493.alcatel.com.au (localhost.alcatel.com.au [127.0.0.1])j1N8os7l087677; Wed, 23 Feb 2005 19:50:54 +1100 (EST) (envelope-from pjeremy@cirb503493.alcatel.com.au) Received: (from pjeremy@localhost)j1N8ortv087676; Wed, 23 Feb 2005 19:50:53 +1100 (EST) (envelope-from pjeremy) Date: Wed, 23 Feb 2005 19:50:53 +1100 From: Peter Jeremy To: =?iso-8859-1?Q?Se=E1n_C=2E?= Farley Message-ID: <20050223085053.GA85422@cirb503493.alcatel.com.au> References: <20050222173013.B26342@thor.farley.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20050222173013.B26342@thor.farley.org> User-Agent: Mutt/1.4.2i cc: freebsd-hackers@freebsd.org Subject: Re: setenv/unsetenv's known memory leak X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Feb 2005 08:51:03 -0000 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