Date: Sat, 15 Jun 2002 02:50:03 -0700 (PDT) From: Bruce Evans <bde@zeta.org.au> To: freebsd-bugs@FreeBSD.org Subject: Re: misc/39314: Memory leak in setenv Message-ID: <200206150950.g5F9o3K32437@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR misc/39314; it has been noted by GNATS. From: Bruce Evans <bde@zeta.org.au> To: Nathan Mower <nmower@verio.net> Cc: freebsd-gnats-submit@FreeBSD.ORG Subject: Re: misc/39314: Memory leak in setenv Date: Sat, 15 Jun 2002 19:47:17 +1000 (EST) On Fri, 14 Jun 2002, Nathan Mower wrote: > >Description: > There is a memory leak in setenv in the case where a name/value pair already exists and the new value is larger than the old one. Setenv does not free the old memory before it malloc's space for the new string. > >How-To-Repeat: > setenv("HOME", "/usr/home/abc", 1); > setenv("HOME", "/usr/home/abcdefghijklmnopqrstuvwxyz", 1); > >Fix: > free the old environ[offset] before malloc'ing the new one. Easier said than done. Patches to free it in previous PRs about this were not accepted, IIRC because it was considered too dangerous to free memory, since this would turn pointers previously returned by getenv() into garbage. setenv() is now specified in a standard that seems to permit freeing (POSIX.1-2001), so it might be time to revisit these patches. Bruce 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?200206150950.g5F9o3K32437>