Date: Sat, 15 Jun 2002 00:50:03 -0700 (PDT) From: David Greenman-Lawrence <dg@root.com> To: freebsd-bugs@FreeBSD.org Subject: Re: misc/39314: Memory leak in setenv Message-ID: <200206150750.g5F7o3O07077@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: David Greenman-Lawrence <dg@root.com> 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 00:44:45 -0700 >>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. This is a well known and unfixable problem. The problem is that environment data may not (and often is not) allocated by malloc - you just don't know, so you can't free it. This is mentioned in the BUGS section in the setenv.3 manual page, although the description of the problem is misleading. -DG D.G.Lawrence Download Technologies, Inc. - http://www.downloadtech.com - (866) 399 8500 TeraSolutions, Inc. - http://www.terasolutions.com - (503) 288 9544 The FreeBSD Project - http://www.freebsd.org Pave the road of life with opportunities. 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?200206150750.g5F7o3O07077>