While playing around with setenv(), I noticed that it can leak memory
when a program overwrites a variable with a larger value.  unsetenv()
will just leak memory.  All of this is documented in their man pages.

The latest PR on this (two PR's mentioned in it are closed):
http://www.freebsd.org/cgi/query-pr.cgi?pr=misc/19406

I could find no apparent reason for continuing to allow for the memory
leak.  The only reason given to allow it was to permit programs to
continue to use the environment variable retrieved by setenv() after the
program had reset or deleted it.

If a program can be assumed to have a persistent pointer, it should be
considered memory that should be freed by the program later.  Yes?
Obviously, this is not the case with the setenv()/unsetenv() API.  Also,
if the pointer is used by a program after it has been overwritten, the
program will be using the wrong value if the value was expanded in size.

After updating an environment variable, the value will be wrong (freed
memory or incorrect value) regardless if the leak is plugged or not.  It
stands to reason that fixing the leak should not be harmful.

In checking a different system, I verified that Linux does not exhibit
this leak.

Here is a test program along with a patch to stop the leak:
http://www.farley.org/freebsd/tmp/setenv.tar.bz2

Seán
--
[EMAIL PROTECTED]
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to