Subject: Re: please review: unsetenv memory leak fix
To: Masaru OKI <oki@netbsd.org>
From: David Laight <david@l8s.co.uk>
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 <bjh21@netbsd.org> 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

-- 
David Laight: david@l8s.co.uk