Date: Thu, 3 Jun 1999 20:00:06 -0700 (PDT) From: Archie Cobbs <archie@whistle.com> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/5604: setenv(3) function has memory leak, other bugs Message-ID: <199906040300.UAA71396@freefall.freebsd.org>
index | next in thread | raw e-mail
The following reply was made to PR bin/5604; it has been noted by GNATS.
From: Archie Cobbs <archie@whistle.com>
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
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199906040300.UAA71396>
