Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Jan 2000 01:30:02 -0800 (PST)
From:      Ruslan Ermilov <ru@FreeBSD.ORG>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/5604: setenv(3) function has memory leak, other bugs
Message-ID:  <200001270930.BAA28994@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/5604; it has been noted by GNATS.

From: Ruslan Ermilov <ru@FreeBSD.ORG>
To: Peter Jeremy <peter.jeremy@alcatel.com.au>,
	Archie Cobbs <archie@whistle.com>, Warner Losh <imp@village.org>,
	Bruce Evans <bde@zeta.org.au>
Cc:  
Subject: Re: bin/5604: setenv(3) function has memory leak, other bugs
Date: Thu, 27 Jan 2000 11:15:31 +0200

 --liOOAslEiF7prFVr
 Content-Type: text/plain; charset=us-ascii
 
 While we are on this topic, how about the following patch to setenv.c?
 
 o Back out rev 1.4 - reallocf() failure will clobber existing `environ'.
 o Do not override `environ' if realloc() fails (Obtained from: OpenBSD).
 o Set `alloced' only when memory was actually allocated.
 
 This will hopefully fix the 2nd part of this PR.
 
 <PS>Any objections if I close PR 10341 as a duplicate of PR 5604?</PS>
 
 -- 
 Ruslan Ermilov		Sysadmin and DBA of the
 ru@ucb.crimea.ua	United Commercial Bank,
 ru@FreeBSD.org		FreeBSD committer,
 +380.652.247.647	Simferopol, Ukraine
 
 http://www.FreeBSD.org	The Power To Serve
 http://www.oracle.com	Enabling The Information Age
 
 --liOOAslEiF7prFVr
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=p
 
 Index: setenv.c
 ===================================================================
 RCS file: /usr/FreeBSD-CVS/src/lib/libc/stdlib/setenv.c,v
 retrieving revision 1.4
 diff -u -p -r1.4 setenv.c
 --- setenv.c	1998/09/16 04:17:45	1.4
 +++ setenv.c	2000/01/27 08:59:52
 @@ -73,16 +73,18 @@ setenv(name, value, rewrite)
  
  		for (p = environ, cnt = 0; *p; ++p, ++cnt);
  		if (alloced) {			/* just increase size */
 -			environ = (char **)reallocf((char *)environ,
 +			p = (char **)realloc((char *)environ,
  			    (size_t)(sizeof(char *) * (cnt + 2)));
 -			if (!environ)
 +			if (!p)
  				return (-1);
 +			environ = p;
  		}
  		else {				/* get new space */
 -			alloced = 1;		/* copy old entries into it */
 +						/* copy old entries into it */
  			p = malloc((size_t)(sizeof(char *) * (cnt + 2)));
  			if (!p)
  				return (-1);
 +			alloced = 1;
  			bcopy(environ, p, cnt * sizeof(char *));
  			environ = p;
  		}
 
 --liOOAslEiF7prFVr--
 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001270930.BAA28994>