Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.85k stars 527 forks source link

@_ leaks under threads #7827

Closed p5pRT closed 14 years ago

p5pRT commented 19 years ago

Migrated from rt.perl.org#34342 (status was 'resolved')

Searchable as RT34342$

p5pRT commented 19 years ago

From stas@stason.org

Created by stas@rabbit.stason.org

This program leaks scalar (this time no -T needed)

#!/usr/bin/perl

use Devel​::Peek; use threads;

threads->new(sub { handler(shift) }\, Foo->new)->join;

sub handler {   Dump $_[0];   #my $r = shift;   my $r = $_[0];   Dump $r;

  threads->new(sub {})->join; }

package Foo;

sub new { bless {}\, __PACKAGE__}

Here we have the parent starting a thread\, which starts another thread (which is similar to what happens if you run a code that starts a thread under mod_perl)

Notice that replacing​:

  my $r = $_[0];

with​:

  my $r = shift;

makes the leak go away. The Dump shows​:

SV = RV(0x80f4508) at 0x8153430   REFCNT = 1   FLAGS = (ROK)   RV = 0x815343c   SV = PVHV(0x813b7f0) at 0x815343c   REFCNT = 1   FLAGS = (OBJECT\,SHAREKEYS)   IV = 0   NV = 0   STASH = 0x8112d2c "Foo"   ARRAY = 0x0   KEYS = 0   FILL = 0   MAX = 7   RITER = -1   EITER = 0x0 SV = RV(0x80f450c) at 0x811417c   REFCNT = 1   FLAGS = (PADBUSY\,PADMY\,ROK)   RV = 0x815343c   SV = PVHV(0x813b7f0) at 0x815343c   REFCNT = 2   FLAGS = (OBJECT\,SHAREKEYS)   IV = 0   NV = 0   STASH = 0x8112d2c "Foo"   ARRAY = 0x80be108   KEYS = 0   FILL = 0   MAX = 7   RITER = -1   EITER = 0x0 Scalars leaked​: 1 leaked​: sv=0x815a6e8 flags=0x0880003 refcnt=0\, Perl interpreter​: 0x8130f80

As you can see the difference between the two is in the flags​:

  FLAGS = (ROK) vs​:   FLAGS = (PADBUSY\,PADMY\,ROK)

I believe that if @​_ is populated\, the thread tries to clone it and leaks it.

Perl Info ``` Flags: category=core severity=high Site configuration information for perl v5.8.6: Configured by stas at Thu Mar 3 21:57:12 EST 2005. Summary of my perl5 (revision 5 version 8 subversion 6) configuration: Platform: osname=linux, osvers=2.6.8.1-12mdk, archname=i686-linux-thread-multi uname='linux rabbit.stason.org 2.6.8.1-12mdk #1 fri oct 1 12:53:41 cest 2004 i686 mobile intel(r) pentium(r) 4 - m cpu 2.00ghz unknown gnulinux ' config_args='-des -Dprefix=/home/stas/perl/5.8.7-ithread -Dusethreads -Doptimize=-g -Duseshrplib -Dusedevel -Accflags=-DDEBUG_LEAKING_SCALARS' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUG_LEAKING_SCALARS -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm', optimize='-g', cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUG_LEAKING_SCALARS -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm' ccversion='', gccversion='3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc libc=/lib/libc-2.3.3.so, so=so, useshrplib=true, libperl=libperl.so gnulibc_version='2.3.3' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/home/stas/perl/5.8.7-ithread/lib/5.8.6/i686-linux-thread-multi/CORE' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Locally applied patches: MAINT23940 @INC for perl v5.8.6: /home/stas/perl/5.8.7-ithread/lib/5.8.6/i686-linux-thread-multi /home/stas/perl/5.8.7-ithread/lib/5.8.6 /home/stas/perl/5.8.7-ithread/lib/site_perl/5.8.6/i686-linux-thread-multi /home/stas/perl/5.8.7-ithread/lib/site_perl/5.8.6 /home/stas/perl/5.8.7-ithread/lib/site_perl . Environment for perl v5.8.6: HOME=/home/stas LANG=en_GB LANGUAGE=en_GB:en LC_ADDRESS=en_CA LC_COLLATE=en_GB LC_CTYPE=en_GB LC_IDENTIFICATION=en_CA LC_MEASUREMENT=en_CA LC_MESSAGES=en_GB LC_MONETARY=en_CA LC_NAME=en_CA LC_NUMERIC=en_CA LC_PAPER=en_CA LC_SOURCED=1 LC_TELEPHONE=en_CA LC_TIME=en_GB LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/usr//bin:/bin:/usr/bin:.:/usr/local/bin:/usr/X11R6/bin/:/usr/games:/home/stas/bin:/home/stas/bin:/usr/local/bin:/usr/X11R6/bin:/usr/java/j2re1.4.0/bin/ PERLDOC_PAGER=less -R PERL_BADLANG (unset) SHELL=/bin/tcsh -- __________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:stas@stason.org http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com ```
p5pRT commented 14 years ago

From @obra

Jerry Hedden reports that the fix in #41138 also fixes this.

From​: "Jerry D. Hedden" \jdhedden@​cpan\.org
Date​: Mon\, 11 Jan 2010 16​:12​:51 -0500
Message-ID​: \1ff86f511001111312m5e03ad12lf5f3878755e943bf@​mail\.gmail\.com

p5pRT commented 14 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 14 years ago

@obra - Status changed from 'open' to 'resolved'