Subject: Re: please review: unsetenv memory leak fix
To: None <>
From: Ben Harris <>
List: tech-userlevel
Date: 06/27/2003 18:42:27
In article <> you write:
>In article <>,
>Masaru OKI <> 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.

Ben Harris                                                   <>
Portmaster, NetBSD/acorn26           <URL:>