Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

Leaked scalars

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


jdhedden at cpan

May 8, 2008, 2:00 PM

Post #1 of 8 (1497 views)
Permalink
Leaked scalars

While working on tests for some new threads::shared
functionality, my test code started generating:

Attempt to free unreferenced scalar: SV 0x15193f8, Perl
interpreter: 0x14b2830 at ./leak.pl line 36.
Attempt to free unreferenced scalar: SV 0x15193c8, Perl
interpreter: 0x14b2830 at ./leak.pl line 36.
Scalars leaked: 2

The following (also attached) reproduces this in blead:

#!/usr/bin/perl
use strict;
use warnings;
use threads;
use threads::shared;

sub _bork {
return $_[0];
}

sub bork
{
if (@_ != 1) {
require Carp;
Carp::croak('Needs one and only one arg');
}
return _bork(shift, {});
}

{
my %hsh = ('foo' => 2);
eval {
bork(%hsh);
};
$@ = undef;
}

my $foo :shared;
$foo = bork(\$foo);

threads->create(sub {
$foo = 1;
})->join();

I can remove 'use strict' and 'use warnings' and still
reproduce the leak, but if I change anything else, the leak
goes away.

Can anyone else reproduce this? If so, can anyone identify
what's leaking?
Attachments: leak.pl (0.40 KB)


davem at iabyn

May 11, 2008, 1:02 PM

Post #2 of 8 (1465 views)
Permalink
Re: Leaked scalars [In reply to]

On Thu, May 08, 2008 at 05:00:06PM -0400, Jerry D. Hedden wrote:
> While working on tests for some new threads::shared
> functionality, my test code started generating:
>
> Attempt to free unreferenced scalar: SV 0x15193f8, Perl
> interpreter: 0x14b2830 at ./leak.pl line 36.
> Attempt to free unreferenced scalar: SV 0x15193c8, Perl
> interpreter: 0x14b2830 at ./leak.pl line 36.
> Scalars leaked: 2
>
> The following (also attached) reproduces this in blead:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use threads;
> use threads::shared;
>
> sub _bork {
> return $_[0];
> }
>
> sub bork
> {
> if (@_ != 1) {
> require Carp;
> Carp::croak('Needs one and only one arg');
> }
> return _bork(shift, {});
> }
>
> {
> my %hsh = ('foo' => 2);
> eval {
> bork(%hsh);
> };
> $@ = undef;
> }
>
> my $foo :shared;
> $foo = bork(\$foo);
>
> threads->create(sub {
> $foo = 1;
> })->join();
>
> I can remove 'use strict' and 'use warnings' and still
> reproduce the leak, but if I change anything else, the leak
> goes away.
>
> Can anyone else reproduce this? If so, can anyone identify
> what's leaking?

I can reproduce. It can be simplified to:

use threads;
use threads::shared;

sub bork {
if (@_) {
package DB;
() = caller(0);
}
return {};
}

{
my %hsh = ('foo' => 2);
eval {
bork(%hsh);
};
}

my $foo :shared;
bork();

threads->create(sub {
$foo;
})->join();


The two AV's that are being double-freed are the thread-cloned copies of
the pad and pad-name AVs of the cloned anon sub passed as an arg to
create().

I've run out of time to look at this any further for the moment.



--
"Procrastination grows to fill the available time"
-- Mitchell's corollary to Parkinson's Law


jdhedden at cpan

May 12, 2008, 7:45 AM

Post #3 of 8 (1466 views)
Permalink
Re: Leaked scalars [In reply to]

Jerry D. Hedden wrote:
> While working on tests for some new threads::shared
> functionality, my test code started generating:
>
> Attempt to free unreferenced scalar: SV 0x15193f8, Perl
> interpreter: 0x14b2830 at ./leak.pl line 36.
> Attempt to free unreferenced scalar: SV 0x15193c8, Perl
> interpreter: 0x14b2830 at ./leak.pl line 36.
> Scalars leaked: 2
>

Dave Mitchell wrote:
> I can reproduce. It can be simplified to:
>
> use threads;
> use threads::shared;
>
> sub bork {
> if (@_) {
> package DB;
> () = caller(0);
> }
> return {};
>
> }
>
> {
> my %hsh = ('foo' => 2);
> eval {
> bork(%hsh);
> };
> }
>
> my $foo :shared;
> bork();
>
> threads->create(sub {
> $foo;
> })->join();
>
> The two AV's that are being double-freed are the thread-cloned copies of
> the pad and pad-name AVs of the cloned anon sub passed as an arg to
> create().
>
> I've run out of time to look at this any further for the moment.

I determined that the offending patch is 32891:
[PATCH] Big slowdown in 5.10 @_ parameter passing


jdhedden at cpan

May 12, 2008, 8:47 AM

Post #4 of 8 (1454 views)
Permalink
Re: Leaked scalars [In reply to]

Jerry D. Hedden wrote:
> While working on tests for some new threads::shared
> functionality, my test code started generating:
>
> Attempt to free unreferenced scalar: SV 0x15193f8, Perl
> interpreter: 0x14b2830 at ./leak.pl line 36.
> Attempt to free unreferenced scalar: SV 0x15193c8, Perl
> interpreter: 0x14b2830 at ./leak.pl line 36.
> Scalars leaked: 2
>

Dave Mitchell wrote:
> I can reproduce. It can be simplified to:
> [SNIP]
> The two AV's that are being double-freed are the thread-cloned copies of
> the pad and pad-name AVs of the cloned anon sub passed as an arg to
> create().
>
> I've run out of time to look at this any further for the moment.

Jerry D. Hedden wrote:
> I determined that the offending patch is 32891:
> [PATCH] Big slowdown in 5.10 @_ parameter passing

Disregard. Using your version, I found that the bug goes further back.


jdhedden at cpan

May 12, 2008, 8:52 AM

Post #5 of 8 (1458 views)
Permalink
Re: Leaked scalars [In reply to]

Jerry D. Hedden wrote:
> While working on tests for some new threads::shared
> functionality, my test code started generating:
>
> Attempt to free unreferenced scalar: SV 0x15193f8, Perl
> interpreter: 0x14b2830 at ./leak.pl line 36.
> Attempt to free unreferenced scalar: SV 0x15193c8, Perl
> interpreter: 0x14b2830 at ./leak.pl line 36.
> Scalars leaked: 2


Dave Mitchell wrote:
> I can reproduce. It can be simplified to:
>
> use threads;
> use threads::shared;
>
> sub bork {
> if (@_) {
> package DB;
> () = caller(0);
> }
> return {};
>
> }
>
> {
> my %hsh = ('foo' => 2);
> eval {
> bork(%hsh);
> };
> }
>
> my $foo :shared;
> bork();
>
> threads->create(sub {
> $foo;
> })->join();
>
>
> The two AV's that are being double-freed are the thread-cloned copies of
> the pad and pad-name AVs of the cloned anon sub passed as an arg to
> create().

Something additional I found, if you add __END__ to the end of the test
script, you get 3 leaked scalars instead of just 2.


rurban at x-ray

May 12, 2008, 9:03 AM

Post #6 of 8 (1454 views)
Permalink
Re: Leaked scalars [In reply to]

2008/5/12 Jerry D. Hedden <jdhedden [at] cpan>:
> Jerry D. Hedden wrote:
> > While working on tests for some new threads::shared
> > functionality, my test code started generating:
> >
> > Attempt to free unreferenced scalar: SV 0x15193f8, Perl
> > interpreter: 0x14b2830 at ./leak.pl line 36.
> > Attempt to free unreferenced scalar: SV 0x15193c8, Perl
> > interpreter: 0x14b2830 at ./leak.pl line 36.
> > Scalars leaked: 2

FYI: You are still thinking that some scalar are leaking. This is wrong.
First, they a AV and a PV (the pad AV and the padname), and 2nd
they are not leaking, they are just freed twice.

There some new opt_free flags in the sv struct to mark them as freed.
Somehow these are not triggered by your XS.


jdhedden at cpan

May 12, 2008, 9:10 AM

Post #7 of 8 (1468 views)
Permalink
Re: Leaked scalars [In reply to]

Jerry D. Hedden wrote:
> While working on tests for some new threads::shared
> functionality, my test code started generating:
>
> Attempt to free unreferenced scalar: SV 0x15193f8, Perl
> interpreter: 0x14b2830 at ./leak.pl line 36.
> Attempt to free unreferenced scalar: SV 0x15193c8, Perl
> interpreter: 0x14b2830 at ./leak.pl line 36.
> Scalars leaked: 2

Dave Mitchell wrote:
> I can reproduce. It can be simplified to:
> [SNIP]
> The two AV's that are being double-freed are the thread-cloned copies of
> the pad and pad-name AVs of the cloned anon sub passed as an arg to
> create().

Jerry D. Hedden wrote:
> Something additional I found, if you add __END__ to the end of the test
> script, you get 3 leaked scalars instead of just 2.

Sorry for the noise. The following is what leaks 3:

use threads;
use threads::shared;

sub bork {
if (@_) {
package DB;
() = caller(0);
}
return {};
}

{
my %hsh = ('foo' => 2);
eval {
bork(%hsh);
};
$@ = undef;
}

my $foo :shared;
bork();

threads->create(sub {
$foo;
})->join();

__END__

Output:

Attempt to free unreferenced scalar: SV 0x14d3dc4, Perl interpreter:
0x14a09f8 at ../../end.pl line 25.
Attempt to free unreferenced scalar: SV 0x14d3dac, Perl interpreter:
0x14a09f8 at ../../end.pl line 25.
Scalars leaked: 3


jdhedden at cpan

May 12, 2008, 12:07 PM

Post #8 of 8 (1468 views)
Permalink
Re: Leaked scalars [In reply to]

Simplified version related to my adding __END__ that just
leaks the one scalar associated with that change:

use threads;

sub bork {
package DB;
() = caller(0);
}

{
my %hsh = ('foo' => 2);
eval {
bork(%hsh);
};
$@ = undef;
}

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

__END__

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.