develooper Front page | perl.perl5.porters | Postings from September 2001

[ID 20010927.010]

From:
pilsl
Date:
September 27, 2001 05:06
Subject:
[ID 20010927.010]
Message ID:
200109271118.f8RBIp402007@limpio.local
~s eval statements fool garbage-collection
This is a bug report for perl from pilsl@goldfisch.at,
generated with the help of perlbug 1.28 running under perl v5.6.0.


-----------------------------------------------------------------
[Please enter your report here]

see also discussion at comp.lang.perl.misc with same subject

I experience the bug only at 5.6.0 and its vanished at 5.6.1, but another guy says, he still has the problem at 5.6.1 under win.
Under 5.6.0 I have the problem at several linuxes and bsd's.

Bug:
if constructing anonymous structures and inserting anonymous subs via a eval-statement, the mem of the whole structure is not released when destroying the structure with undef.

Workarounds: (that costs time in big structures)
- manually undef the nodes holding the anonymous subs before undef the structure
- manually recursive deletion of the whole structure

severity is high, cause this is a common contruct in mod_perl-environments that makes apache memleaking like a sieve ...

sample-script (just to give an idea. increase nummber of loops to be sure that is not a free()-Problem of the running OS.) 

....................................................
#!/usr/bin/perl -w
use strict;

foreach (0..0)   # extend to increase effect
{
  allocate();
}

sub allocate
{
  print "===============\n";
  print `ps -o vsize,rss -p $$ | tail -1`;
  my $ptr={};tr->{big}=[];
  $#{$ptr->{big}}=5000000;
  def2($ptr);
  print &{$ptr->{test}->{func2}}(5),"\n";
  print `ps -o vsize,rss -p $$ | tail -1`;
  #  undef $ptr->{test}->{func2};   # Poss 1 this is enough to kill the whole structure in the next statement
  undef $ptr;                     # Poss 2 this will not delete the structure without the previous statement
  print `ps -o vsize,rss -p $$ | tail -1`;
}
sub def2 {
  my $ptr=shift;
  my $cmd='$ptr->{test}->{func2}=sub{return $_[0]+4};';
  #  $ptr->{test}->{func2}=sub{return $_[0]+4};        # Poss A with this statement there is no Problem
  eval $cmd;                                         # Poss B this statement fools garbage collection
}
...............................................

output:  (shows mainly needed mem by task and the 9 ist just output of the testfunction)
In the first case the mem is not released - in the second it is.
The putput of 'ps' is not a real proove, but you can increase the loop.

$./mem.pl
 2824 1304
 9
 22360 20904
$vi # uncomment 19
$./mem.pl
===============
 2824 1304
 9
 22360 20904
  2828 1376





[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=high
---
Site configuration information for perl v5.6.0:

Configured by fg at Wed Apr  4 18:57:12 CEST 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.1-20mdksmp, archname=i386-linux
    uname='linux bi.mandrakesoft.com 2.4.1-20mdksmp #1 smp tue feb 20 19:21:17 cet 2001 i686 unknown '
    config_args='-des -Darchname=i386-linux -Dd_dosuid -Ud_csh -Duseshrplib -Doptimize=-O3 -fomit-frame-pointer -pipe -mcpu=pentiumpro -march=i586 -ffast-math -Dprefix=/usr -Di_ndbm -Di_gdbm -Di_shadow -Di_syslog -Uuselargefiles -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/lib/perl5/man/man3'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=undef 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cc', optimize='-O3 -fomit-frame-pointer -pipe -mcpu=pentiumpro -march=i586 -ffast-math', gccversion=2.96 20000731 (Linux-Mandrake 8.0 2.96-0.47mdk)
    cppflags='-fno-strict-aliasing'
    ccflags ='-fno-strict-aliasing'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lc -lcrypt
    libc=/lib/libc-2.2.2.so, so=so, useshrplib=true, libperl=libperl.so
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.6.0/i386-linux/CORE'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.6.0:
    /usr/lib/perl5/5.6.0/i386-linux
    /usr/lib/perl5/5.6.0
    /usr/lib/perl5/site_perl/5.6.0/i386-linux
    /usr/lib/perl5/site_perl/5.6.0
    /usr/lib/perl5/site_perl
    .

---
Environment for perl v5.6.0:
    HOME=/home/pilsl
    LANG=en
    LANGUAGE=en_US:en
    LC_COLLATE=en_US
    LC_CTYPE=en_US
    LC_MESSAGES=en_US
    LC_MONETARY=en_US
    LC_NUMERIC=en_US
    LC_TIME=en_US
    LD_LIBRARY_PATH=/usr/lib
    LOGDIR (unset)
    PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/games:/usr/X11R6/bin:/usr/games
    PERL_BADLANG (unset)
    SHELL=/bin/bash




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