From owner-freebsd-bugs Thu Jun 3 20: 0:12 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 4D86915A74 for ; Thu, 3 Jun 1999 20:00:06 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id UAA71396; Thu, 3 Jun 1999 20:00:06 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Date: Thu, 3 Jun 1999 20:00:06 -0700 (PDT) Message-Id: <199906040300.UAA71396@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Archie Cobbs Subject: Re: bin/5604: setenv(3) function has memory leak, other bugs Reply-To: Archie Cobbs Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/5604; it has been noted by GNATS. From: Archie Cobbs To: ghelmer@cs.iastate.edu (Guy Helmer) Cc: freebsd-gnats-submit@freebsd.org Subject: Re: bin/5604: setenv(3) function has memory leak, other bugs Date: Thu, 3 Jun 1999 19:54:17 -0700 (PDT) Guy Helmer writes: > Has there been progress on a fix, or should the behavior be left as-is? > PR bin/10341 references the same problem. The fact of the matter is that (according to the forces of inertia) "expected behavior" *implies* a memory leak. This is because if you do something like this: char *s; s = getenv("FOO"); setenv("FOO", "new contents", 1); then the pointer "s" is supposed to still be valid. That is, the setenv() routine is not allowed to call free(s). This is what the FreeBSD forces of inertia have claimed anyway. I think there must be very few programs that rely on this, and the ones that do are bogus anyway, and we should just fix it. Morever, as I remember it was never made clear what POSIX specifies about this. But the FOI prevailed when I tried to fix this before. A workaround is to never overwrite a string with a shorter string. Overwrite with a string of the same length as the original and then sprintf() the shorter string onto the new one. -Archie ___________________________________________________________________________ Archie Cobbs * Whistle Communications, Inc. * http://www.whistle.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message