Subject: Re: please review: unsetenv memory leak fix
To: None <christos@zoulas.com>
From: Ben Harris <bjh21@netbsd.org>
List: tech-userlevel
Date: 06/27/2003 18:42:27
In article <HH5Hwv.L6y@tac.nyc.ny.us> you write:
>In article <20030628012855.AC2C.OKI@netbsd.org>,
>Masaru OKI <oki@netbsd.org> wrote:
>>unsetenv(3) doesn't call free(3) with environment variable string.
>>following diff is fixed the problem.
>>If it is looks good, I'll commit it later.
>
>It could break existing code that accesses environ directly...

This could be improved by remembering the address of the block that was
allocated by setenv, and only trying to free anything if the address hasn't
changed by the time unsetenv is called.

Incidentally, POSIX says:

# If the application modifies environ or the pointers to which it points, the
# behavior of unsetenv() is undefined.
<http://www.opengroup.org/onlinepubs/007904975/functions/unsetenv.html>

-- 
Ben Harris                                                   <bjh21@netbsd.org>
Portmaster, NetBSD/acorn26           <URL:http://www.netbsd.org/Ports/acorn26/>