You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2004/04/21 05:21:23 UTC

[Fwd: leaking sv when perl_clone is used after some code is run]

I'm hunting down those numerous mysterious leak reports we have at the 
shutdown under threaded mpm. One of them is easily reproduced with the 
following minimal config file:

PerlModule Apache2
<Perl >
sub foo { }
</Perl>

This is unfortunately a bug in perl. The rest is explained in the bug report 
below.

-------- Original Message --------
Subject: leaking sv when perl_clone is used after some code is run
Date: Tue, 20 Apr 2004 20:15:33 -0700
From: Stas Bekman <st...@stason.org>
Organization: Hope, Humanized
To: perlbug@perl.org

This is a bug report for perl from stas@rabbit.stason.org,
generated with the help of perlbug 1.35 running under perl v5.8.4.


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

The followinig problem is reproduced with any 5.8-5.9 w/ithreads.

doing the sequence:

1. create perl
2. eval_pv "sub foo"
3. perl_clone

causes a scalar leak

Here is a program to reproduce:

/* clone.c */
#include <EXTERN.h>
#include <perl.h>

/*
  * gcc -o clone clone.c `perl-5.8.0-ithread -MExtUtils::Embed -e ccopts -e
ldopts` -Wall -g
  */

#define TEST "sub foo {}"

int main(int argc, char **argv, char **env)
{
      char *embedding[] = { "", "-le", "0" };
      PerlInterpreter *perl1 = perl_alloc();
      PerlInterpreter *perl2;

      PERL_SET_CONTEXT(perl1);
      perl_construct(perl1);

      perl_parse(perl1, NULL, 3, embedding, (char **)NULL);
      /* DynaLoader must be preloaded before perl_clone, if DynaLoader
       * is to be required later */

      Perl_eval_pv(perl1, TEST, TRUE); /* loaded only by the first perl */

      perl2 = perl_clone(perl1, CLONEf_KEEP_PTR_TABLE);

      PERL_SET_CONTEXT(perl2);
      perl_destruct(perl2);
      perl_free(perl2);

      PERL_SET_CONTEXT(perl1);
      perl_destruct(perl1);
      perl_free(perl1);

      exit(0);
}

The critical part is

#define TEST "sub foo {}"

which gets eval'ed, the problem doesn't appear if some other code is in
there. I've modied the debug code to call sv_dump to the leaked scalar, so
this is what I get when running this program:

./clone                                      Attempt to free temp
prematurely: SV 0x8075bd8, Perl interpreter: 0x8066a10 during global
destruction.
Scalars leaked: 1
leaked: 0x8075bd8, Perl interpreter: 0x8066a10
SV = PVCV(0x8076178) at 0x8075bd8
   REFCNT = 0
   FLAGS = (TEMP,UNIQUE)
   IV = 0
   NV = 0
   COMP_STASH = 0x0
   ROOT = 0x0
   XSUB = 0x0
   XSUBANY = 0
   GVGV::GV = 0x0
   FILE = "(null)"
   DEPTH = 0
   FLAGS = 0x10
   OUTSIDE_SEQ = 0
   PADLIST = 0x8075be4
   OUTSIDE = 0x8075c08 (UNIQUE)

My guess is that there is a bug in perl_clone(), and something is not properly
cloned.

Unfortunately I wasn't able to come up with a pure perl example to reproduce
the problem. I suppose this is only triggered with embedded perl.

If you are interested where the problem was detected, it's obviously under
mod_perl 2. The following config section triggers this problem under
threaded mpm Apache2:

<Perl>
sub foo { }
</Perl>


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

Configured by stas at Fri Apr 16 18:44:17 PDT 2004.

Summary of my perl5 (revision 5 version 8 subversion 4) configuration:
   Platform:
     osname=linux, osvers=2.6.3-7mdk, archname=i686-linux-thread-multi
     uname='linux rabbit.stason.org 2.6.3-7mdk #1 wed mar 17 15:56:42 cet 2004
i686 unknown unknown gnulinux '
     config_args='-des -Dprefix=/home/stas/perl/5.8.4-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 -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 -I/usr/local/include
-I/usr/include/gdbm'
     ccversion='', gccversion='3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)',
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.4-ithread/lib/5.8.4/i686-linux-thread-multi/CORE'
     cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
     RC2

---
@INC for perl v5.8.4:
     /home/stas/perl/5.8.4-ithread/lib/5.8.4/i686-linux-thread-multi
     /home/stas/perl/5.8.4-ithread/lib/5.8.4
     /home/stas/perl/5.8.4-ithread/lib/site_perl/5.8.4/i686-linux-thread-multi
     /home/stas/perl/5.8.4-ithread/lib/site_perl/5.8.4
     /home/stas/perl/5.8.4-ithread/lib/site_perl
     .

---
Environment for perl v5.8.4:
     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_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


-- 
__________________________________________________________________
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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [Fwd: leaking sv when perl_clone is used after some code is run]

Posted by Stas Bekman <st...@stason.org>.
>>+1, plus, i'll add a comment to why this is here, later once we get a perl bug 
>>id assigned

> Yeah, I was looking around trying to find the perl bug id assigned to
> this thing until I realized there wasn't one yet. So I guess I could at
> least temporarly link to the bug report p5p. Stas do you have a link to it ?

That's the thing - there is none, bugreports are moderated. Once it hits p5p 
there will be a link. But don't worry, I'll take care of it, since I also 
document this in the troubleshooting section. while we can workaround it users 
will most certainly get this problem with their own setups.

>>Whoah, we are back to the clean log under threaded mpm.
> 
> 
> And threaded builds startup in 5 seconds and less for me, yay!

:) Time to make a new release :)

You have a monstrous machine. On my notebook it used to start in about 3 
minutes when unloaded (and timeout when loaded), now only 28 secs :)

__________________________________________________________________
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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [Fwd: leaking sv when perl_clone is used after some code is run]

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.

Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> 
> 
>>>Philippe, did you by chance watch the error log when testing that 
>>>change? I guess you did, but not with the worker/threaded mpm. :)
>>
>>
>>
>>I must have been running prefork that time. Sorry, should have caught this.
> 
> 
> no worries, I have the same issue with worker :)
> 
> 
>>>my bug report still didn't make it to p5p. But even when it does I 
>>>doubt anybody is going to look at it. threads support is pretty dead 
>>>at the moment at p5p.
>>
>>
>>Suggest this patch to just move the tied sub declaration to one of the 
>>startup-scripts instead of in a <Perl > block
> 
> 
> +1, plus, i'll add a comment to why this is here, later once we get a perl bug 
> id assigned

Yeah, I was looking around trying to find the perl bug id assigned to
this thing until I realized there wasn't one yet. So I guess I could at
least temporarly link to the bug report p5p. Stas do you have a link to it ?

> 
>>+#For the tied %Location in <Perl > sections
>>+use Tie::Hash;
>>+@Tie::PerlSection::ISA = qw(Tie::StdHash);
>>+sub Tie::PerlSection::FETCH {
>>+    my ($hash, $key) = @_;
>>+    if ($key eq '/tied') {
>>+        return 'TIED';
>>+    }
>>+    return $hash->{$key};
>>+}
> 
> 
> Whoah, we are back to the clean log under threaded mpm.

And threaded builds startup in 5 seconds and less for me, yay!

> Randy, is that the case on win32? no leaks/early freeing/etc perl reports?
> 
> __________________________________________________________________
> 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
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
> For additional commands, e-mail: dev-help@perl.apache.org
> 
> 

Re: [Fwd: leaking sv when perl_clone is used after some code is run]

Posted by Stas Bekman <st...@stason.org>.
Philippe M. Chiasson wrote:

>> Philippe, did you by chance watch the error log when testing that 
>> change? I guess you did, but not with the worker/threaded mpm. :)
> 
> 
> 
> I must have been running prefork that time. Sorry, should have caught this.

no worries, I have the same issue with worker :)

>> my bug report still didn't make it to p5p. But even when it does I 
>> doubt anybody is going to look at it. threads support is pretty dead 
>> at the moment at p5p.
> 
> 
> Suggest this patch to just move the tied sub declaration to one of the 
> startup-scripts instead of in a <Perl > block

+1, plus, i'll add a comment to why this is here, later once we get a perl bug 
id assigned

> +#For the tied %Location in <Perl > sections
> +use Tie::Hash;
> +@Tie::PerlSection::ISA = qw(Tie::StdHash);
> +sub Tie::PerlSection::FETCH {
> +    my ($hash, $key) = @_;
> +    if ($key eq '/tied') {
> +        return 'TIED';
> +    }
> +    return $hash->{$key};
> +}

Whoah, we are back to the clean log under threaded mpm.

Randy, is that the case on win32? no leaks/early freeing/etc perl reports?

__________________________________________________________________
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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [Fwd: leaking sv when perl_clone is used after some code is run]

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Stas Bekman wrote:

> Stas Bekman wrote:
>
>> I'm hunting down those numerous mysterious leak reports we have at 
>> the shutdown under threaded mpm. One of them is easily reproduced 
>> with the following minimal config file:
>>
>> PerlModule Apache2
>> <Perl >
>> sub foo { }
>> </Perl>
>>
>> This is unfortunately a bug in perl. The rest is explained in the bug 
>> report below.
>
>
> So we may need to revert this change:
>
> Added test to ensure <Perl> sections can have things like %Location
> tied [Gozer]
>
> or rework it so perl doesn't report leaks, as it's really bad to have 
> these leaks reported. I first thougt it was a leak from my recent 
> revamp of the END blocks, wasting tons of time, just to realize that 
> it wasn't my change :(

> Philippe, did you by chance watch the error log when testing that 
> change? I guess you did, but not with the worker/threaded mpm. :)


I must have been running prefork that time. Sorry, should have caught this.

> my bug report still didn't make it to p5p. But even when it does I 
> doubt anybody is going to look at it. threads support is pretty dead 
> at the moment at p5p.

Suggest this patch to just move the tied sub declaration to one of the 
startup-scripts instead of in a <Perl > block

Index: t/conf/extra.last.conf.in
===================================================================
RCS file: /home/cvs/modperl-2.0/t/conf/extra.last.conf.in,v
retrieving revision 1.20
diff -u -I$Id -r1.20 extra.last.conf.in
--- t/conf/extra.last.conf.in   27 Mar 2004 07:43:39 -0000      1.20
+++ t/conf/extra.last.conf.in   22 Apr 2004 23:00:26 -0000
@@ -13,19 +13,6 @@
 </Perl>

 <Perl >
-package Tie::PerlSection;
-use Tie::Hash;
-@ISA = (Tie::StdHash);
-sub FETCH {
-    my ($hash, $key) = @_;
-    if ($key eq '/tied') {
-        return 'TIED';
-    }
-    return $hash->{$key};
-}
-</Perl>
-
-<Perl >
 #Test tied %Location
 tie %Location, 'Tie::PerlSection';
 $Location{'/tied'} = 'test_tied';
Index: t/conf/modperl_extra.pl
===================================================================
RCS file: /home/cvs/modperl-2.0/t/conf/modperl_extra.pl,v
retrieving revision 1.44
diff -u -I$Id -r1.44 modperl_extra.pl
--- t/conf/modperl_extra.pl     22 Apr 2004 21:36:11 -0000      1.44
+++ t/conf/modperl_extra.pl     22 Apr 2004 23:00:26 -0000
@@ -356,4 +356,16 @@
     %before = %after;
 }

+#For the tied %Location in <Perl > sections
+use Tie::Hash;
+@Tie::PerlSection::ISA = qw(Tie::StdHash);
+sub Tie::PerlSection::FETCH {
+    my ($hash, $key) = @_;
+    if ($key eq '/tied') {
+        return 'TIED';
+    }
+    return $hash->{$key};
+}
+
+
 1;


> __________________________________________________________________
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
> For additional commands, e-mail: dev-help@perl.apache.org
>
>


Re: [Fwd: leaking sv when perl_clone is used after some code is run]

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> I'm hunting down those numerous mysterious leak reports we have at the 
> shutdown under threaded mpm. One of them is easily reproduced with the 
> following minimal config file:
> 
> PerlModule Apache2
> <Perl >
> sub foo { }
> </Perl>
> 
> This is unfortunately a bug in perl. The rest is explained in the bug 
> report below.

So we may need to revert this change:

Added test to ensure <Perl> sections can have things like %Location
tied [Gozer]

or rework it so perl doesn't report leaks, as it's really bad to have these 
leaks reported. I first thougt it was a leak from my recent revamp of the END 
blocks, wasting tons of time, just to realize that it wasn't my change :(

Philippe, did you by chance watch the error log when testing that change? I 
guess you did, but not with the worker/threaded mpm. :)

my bug report still didn't make it to p5p. But even when it does I doubt 
anybody is going to look at it. threads support is pretty dead at the moment 
at p5p.

__________________________________________________________________
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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org