From pdp@nl.demon.net  Tue Jun 20 11:29:17 2000
Return-Path: <pdp@nl.demon.net>
Received: from binnen.mail.nl.demon.net (binnen.mail.nl.demon.net [194.159.72.192])
	by hub.freebsd.org (Postfix) with ESMTP id 8C74B37B829
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 20 Jun 2000 11:29:14 -0700 (PDT)
	(envelope-from pdp@nl.demon.net)
Received: from samhain.noc.nl.demon.net ([194.159.72.214] ident=exim)
	by binnen.mail.nl.demon.net with esmtp (Exim 3.13 #1)
	id 134Skw-000CLP-00
	for FreeBSD-gnats-submit@freebsd.org; Tue, 20 Jun 2000 20:28:14 +0200
Received: from pdp by samhain.noc.nl.demon.net with local id 134Skv-0008h2-00 
	for FreeBSD-gnats-submit@freebsd.org; Tue, 20 Jun 2000 20:28:13 +0200
Message-Id: <E134Skv-0008h2-00@samhain.noc.nl.demon.net>
Date: Tue, 20 Jun 2000 20:28:13 +0200
From: Phil Pennock <phil.pennock@globnix.org>
To: FreeBSD-gnats-submit@freebsd.org
Subject: setenv() allocates memory which is not freed by unsetenv()
X-Send-Pr-Version: 3.2

>Number:         19406
>Category:       kern
>Synopsis:       [libc] setenv(3) allocates memory which is not freed by unsetenv()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    scf
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 20 11:30:00 PDT 2000
>Closed-Date:    Sun Jan 27 08:48:36 UTC 2008
>Last-Modified:  Sun Jan 27 08:48:36 UTC 2008
>Originator:     Phil Pennock
>Release:        FreeBSD 3.4-STABLE i386
>Organization:
n/a
>Environment:
Any
>Description:
setenv() allocates memory for variable.  unsetenv() does not free that memory.
>How-To-Repeat:
Compile the code below, run, find pid and use "ps up <pid>" to see the RSS
grow without apparent bound.

#include <stdlib.h>
#include <unistd.h>

#define Name "testing"
#define Value "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

int
main (int argc, char *argv[])
{
	int i;

	while(1) {
		for (i=0; i<1000; ++i) {
			setenv(Name, Value, 1);
			unsetenv(Name);
		}
		sleep(1);
	}
	return 0;
}

>Fix:
Anyone want to think how many old programs depend on some buggy aspect of the
memory allocation involved here?

>Release-Note:
>Audit-Trail:

From: David Malone <dwmalone@maths.tcd.ie>
To: Phil Pennock <pdp@nl.demon.net>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: misc/19406: setenv() allocates memory which is not freed by unsetenv()
Date: Tue, 20 Jun 2000 19:36:25 +0100

 On Tue, Jun 20, 2000 at 08:28:13PM +0200, Phil Pennock wrote:
 
 > Anyone want to think how many old programs depend on some buggy aspect of the
 > memory allocation involved here?
 
 I believe this is required by some spec (probably POSIX), and has been
 discussed several times on the FreeBSD lists. I think the conclusion was
 that the current implimentation was correct. See:
 
 http://www.FreeBSD.org/cgi/query-pr.cgi?pr=5604
 http://www.FreeBSD.org/cgi/query-pr.cgi?pr=10341
 
 	David.
 

From: Phil Pennock <pdp@nl.demon.net>
To: David Malone <dwmalone@maths.tcd.ie>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: misc/19406: setenv() allocates memory which is not freed by unsetenv()
Date: Tue, 20 Jun 2000 20:51:16 +0200

 On Tue 20 Jun 2000 (19:36 +0100), David Malone wrote:
 > On Tue, Jun 20, 2000 at 08:28:13PM +0200, Phil Pennock wrote:
 > > Anyone want to think how many old programs depend on some buggy aspect of the
 > > memory allocation involved here?
 > 
 > I believe this is required by some spec (probably POSIX), and has been
 > discussed several times on the FreeBSD lists. I think the conclusion was
 > that the current implimentation was correct. See:
 
 Not sure about that.  But going to <http://www.opengroup.org/> and
 finding the Single UNIX Specification online and searching for relevant
 manual pages, putenv() is there whilst setenv() isn't.  Sorry, their
 copyright prevents me posting a full URL which includes some form of
 session-ID.
 
 The implementation of putenv() on setenv() appears to not comply with
 this spec.  This is what led me to find this in the first place.
 
 *sighs*
 -- 
 Phil Pennock                        <pdp@nl.demon.net> <Phil.Pennock@thus.net>
 Demon Internet Nederland -- Network Operations Centre -- Systems Administrator
 Libertes philosophica.
 Sales: +31 20 422 20 00                                Support: 0800 33 6666 8
 
Responsible-Changed-From-To: freebsd-bugs->scf 
Responsible-Changed-By: scf 
Responsible-Changed-When: Sat Aug 4 13:58:57 CDT 2007 
Responsible-Changed-Why:  
Take ownership of this PR.  I believe I fixed it in PR kern/99826. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=19406 
State-Changed-From-To: open->feedback 
State-Changed-By: scf 
State-Changed-When: Sat Aug 4 21:05:58 CDT 2007 
State-Changed-Why:  
Would you let me know if the change in kern/99826 is satisfactory to 
close this PR?  The memory leak shown in your example program should be 
fixed by this change (in 7-CURRENT). 

kern/99826:  http://www.freebsd.org/cgi/query-pr.cgi?pr=99826&cat=kern 

http://www.freebsd.org/cgi/query-pr.cgi?pr=19406 
State-Changed-From-To: feedback->closed 
State-Changed-By: linimon 
State-Changed-When: Sun Jan 27 08:47:08 UTC 2008 
State-Changed-Why:  
Feedback timeout (> 4 months). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=19406 
>Unformatted:
