develooper Front page | perl.perl5.porters | Postings from November 1999

Re: [ID 19991116.002] perl5.005_02: my_setenv() and Term::ReadLine::Gnu

From:
Ilya Zakharevich
Date:
November 17, 1999 16:40
Subject:
Re: [ID 19991116.002] perl5.005_02: my_setenv() and Term::ReadLine::Gnu
Message ID:
19991117194027.A3801@monk.mps.ohio-state.edu
On Thu, Nov 18, 1999 at 01:31:11AM +0100, Joerg Schumacher wrote:
> > > But the free() is called with the pointer to a memory block which has
> > > never been malloc()'ed by perl.  
> > 
> > You look utterly confused.  First you claim that this is not a problem
> > with several mismatched malloc()s, now you say that it is.
> 
> Nope.  All I say is that you MUST NOT free() memory which hasn't been
> malloc()ed before.  The memory block which perl tries to free() in
> Safefree() is the original block passed via exec(2).  This block
> hasn't been malloc()ed and therefore perl must not free() it.

OK, now it is us who look utterly confused...  I was pretty sure that
documentation of putenv() states that it free()s the old value, but
most probably it just leaks...

So your solution involves a static variable.  Hmm...  Since
environment coming from main() is a global property, it is probably
what should have been done.

But nevertheless, your solution is a leak, since the environment set
in the library will never be free()d.  On the other hand, what else
can we say instead of "tough luck": the library might have put a
static string into environment too...

Ilya



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About