Subject: Re: please review: unsetenv memory leak fix
To: Masaru OKI <>
From: David Laight <>
List: tech-userlevel
Date: 06/28/2003 09:25:54
On Sat, Jun 28, 2003 at 04:25:29PM +0900, Masaru OKI wrote:
> On Fri, 27 Jun 2003 18:42:27 +0100
> Ben Harris <> wrote:
> > 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.
> Thank you for comments, and another bug was found by my own review.
> I made new patch.  It depends on the offset.

There are several bugs lurking still:

1) unsetenv will dump if the env hasn't been expanded.
2) setenv will dump if an item is overwritten with a longer string
   and the env hasn't been expanded.
3) you should probably check that the saved pointer matches the env one
   before freeing it.

Use the presence of the new array - no need to export 'alloced'.


David Laight: