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

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

Joerg Schumacher
November 17, 1999 16:08
Re: [ID 19991116.002] perl5.005_02: my_setenv() and Term::ReadLine::Gnu
Message ID:

> > No, the scenario is as follows:
> > 
> >    1) perl_parse() saves the pointer to the environment in PL_origenviron
> >    2) some extension interface (here Term::ReadLine::Gnu) is called
> >       and does modify the pointer to the environment via putenv(3)
> >    3) the perlscript tries to assign a new value to an environment
> >       variable and perl therefore calls my_setenv()
> >    4) my_setenv() does check if it needs to copy the environment but
> >       the check returns false since (environ != PL_origenviron)
> >    5) my_setenv() calls Safefree() and free()s some unallocated memory
> *What* it calls Safefree() on?  

Well, the appended perl-script-testcase had four lines of code, one of them is 

   $ENV{PATH} ="foo";

so the Safefree() has been called on environ[i] with i pointing PATH.  
The testcase dumps only core if LINES and COLUMNS aren't defined in the 
env before starting the script so that the putenv() called by 
set_lines_and_columns() in readline-4.0:shell.c has to call malloc() and  
therefore modifies the global var char **environ.

> How can it be that this is unallocated?

Since it has never been malloc()ed by perl due to the weak test in 

> Judging by what you wrote, you are running some old version of Perl,
> such as 5.005_03.  

This is the stable version, can't be that old?

> In 5.005_50 I can see that the only Safefree() is
> done on environ[i].  Due to documentation of putenv() I can see,
> environ[i] *should be* malloced.

But the free() is called with the pointer to a memory block which has
never been malloc()'ed by perl.  

> I think you need to concentrate on these questions.

free()ing some memory which has never been malloc()ed is asking
for trouble.  IMHO this is out of question.

Kind regards,

 Gaertner Datensysteme                         38114 Braunschweig 
 Joerg Schumacher                              Hamburger Str. 273a
 Tel: 0531-2335555          		       Fax: 0531-2335556 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About