| Summary: | [libc] setenv(3) allocates memory which is not freed by unsetenv() | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Phil Pennock <phil.pennock> |
| Component: | kern | Assignee: | Sean Farley <scf> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 3.4-STABLE | ||
| Hardware: | Any | ||
| OS: | Any | ||
On Tue, Jun 20, 2000 at 08:28:13PM +0200, Phil Pennock wrote: > Anyone want to think how many old programs depend on some buggy aspect of the > memory allocation involved here? I believe this is required by some spec (probably POSIX), and has been discussed several times on the FreeBSD lists. I think the conclusion was that the current implimentation was correct. See: http://www.FreeBSD.org/cgi/query-pr.cgi?pr=5604 http://www.FreeBSD.org/cgi/query-pr.cgi?pr=10341 David. On Tue 20 Jun 2000 (19:36 +0100), David Malone wrote: > On Tue, Jun 20, 2000 at 08:28:13PM +0200, Phil Pennock wrote: > > Anyone want to think how many old programs depend on some buggy aspect of the > > memory allocation involved here? > > I believe this is required by some spec (probably POSIX), and has been > discussed several times on the FreeBSD lists. I think the conclusion was > that the current implimentation was correct. See: Not sure about that. But going to <http://www.opengroup.org/> and finding the Single UNIX Specification online and searching for relevant manual pages, putenv() is there whilst setenv() isn't. Sorry, their copyright prevents me posting a full URL which includes some form of session-ID. The implementation of putenv() on setenv() appears to not comply with this spec. This is what led me to find this in the first place. *sighs* -- Phil Pennock <pdp@nl.demon.net> <Phil.Pennock@thus.net> Demon Internet Nederland -- Network Operations Centre -- Systems Administrator Libertes philosophica. Sales: +31 20 422 20 00 Support: 0800 33 6666 8 Responsible Changed From-To: freebsd-bugs->scf Take ownership of this PR. I believe I fixed it in PR kern/99826. State Changed From-To: open->feedback Would you let me know if the change in kern/99826 is satisfactory to close this PR? The memory leak shown in your example program should be fixed by this change (in 7-CURRENT). kern/99826: http://www.freebsd.org/cgi/query-pr.cgi?pr=99826&cat=kern State Changed From-To: feedback->closed Feedback timeout (> 4 months). |
setenv() allocates memory for variable. unsetenv() does not free that memory. Fix: Anyone want to think how many old programs depend on some buggy aspect of the memory allocation involved here? How-To-Repeat: Compile the code below, run, find pid and use "ps up <pid>" to see the RSS grow without apparent bound. #include <stdlib.h> #include <unistd.h> #define Name "testing" #define Value "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" int main (int argc, char *argv[]) { int i; while(1) { for (i=0; i<1000; ++i) { setenv(Name, Value, 1); unsetenv(Name); } sleep(1); } return 0; }