Closed p5pRT closed 14 years ago
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.
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
The RT System itself - Status changed from 'new' to 'open'
@obra - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#34342 (status was 'resolved')
Searchable as RT34342$