Re: [Boston.pm] perl 5.10 memory leak?
Duane Bronson <[email protected]>
| Newsgroups | gmane.comp.lang.perl.perl-mongers.boston |
|---|---|
| Message-ID | <[email protected]> |
Yes! That fixes it. I'm not sure how 'local' makes a difference here, but it appears to work.
I figured out how to override the built-in version::boolean to fix it as well, but I like the "local" solution better. Some of my testing shown here:
Failure exposing leak:
[mazu@cvm ~]$ perl -wE 'use Test::LeakTrace; use Data::Dumper; $foo = version->new(v1.2.3); say @foo = ((Dumper leaked_refs { 1 if ($foo) }) || "clean")'
$VAR1 = \'0';
$VAR2 = \bless( {
'original' => '0',
'version' => [
0
]
}, 'version' );
$VAR3 = ${$VAR2}->{'version'};
$VAR4 = ${$VAR2};
$VAR5 = \${$VAR2}->{'version'}->[0];
$VAR6 = \${$VAR2}->{'original'};
$VAR7 = \${$VAR2}->{'version'};
Solution using "local":
[mazu@cvm ~]$ perl -wE 'use Test::LeakTrace; use Data::Dumper; $foo = version->new(v1.2.3); say @foo = ((Dumper leaked_refs { local $foo; 1 if ($foo) }) || "clean")'
clean
Solution fixing version::boolean:
[mazu@cvm ~]$ perl -wE 'use Test::LeakTrace; use Data::Dumper; { no warnings "redefine"; *{"version::(bool"} = sub { for my $v (@{$_[0]->{version}}) { return 1 if $v } return; }} $foo = version->new(v1.2.3); say @foo = ((Dumper leaked_refs { 1 if ($foo) }) || "clean")'
clean
Also, I found another leak in comparing a version object to a non-version object ($^V eq $]) when playing around with Mike Small's suggestion. Looks like this was also fixed at some point.
Duane
> On Dec 14, 2016, at 2:58 PM, Ben Tilly <[email protected]> wrote:
>
> This is nasty. Does the following fix work for you?
>
> use IO::All;
> if ($^V lt v5.16.0) {
> no warnings 'redefine';
> my $orig_destroy = *IO::All::DESTROY{CODE};
> *IO::All::DESTROY = sub {
> my $self = shift;
> local $^V;
> $orig_destroy->($self, @_) if $orig_destroy;
> };
> }
>
> This temporarily replaces $^V with the empty string which does the right thing with the current version check. Hopefully your Perl gets upgraded before IO::All has a new version check in DESTROY that this hack doesn't work.
>
> On Wed, Dec 14, 2016 at 7:44 AM, Duane Bronson <[email protected] <mailto:[email protected]>> wrote:
> Ahh - the bug is in universal.c <https://perl5.git.perl.org/perl.git/blobdiff/202e6ee2081e3a898537656cda1148d9aded394d..bcb2959f0:/universal.c> in XS_version_boolean. Can I override that in perl code? Something like this?
>
> sub version::boolean {
> ...
> }
>
> Thanks, Matthew! I'd like to know how you found that. Google didn't help me.
> Duane
>
>> On Dec 14, 2016, at 12:58 AM, Matthew Horsfall (alh) <[email protected] <mailto:[email protected]>> wrote:
>>
>> On Wed, Dec 14, 2016 at 12:55 AM, Matthew Horsfall (alh)
>> <[email protected] <mailto:[email protected]>> wrote:
>>> On Tue, Dec 13, 2016 at 6:41 PM, Ben Tilly <[email protected] <mailto:[email protected]>> wrote:
>>>> Is the leak in not calling untie, or in looking at $^V?
>>>
>>> The leak is in looking at $^V. This was broken in 5.10.0 and fixed in 5.16.0.
>>
>> In boolean context.
>>
>> my $x = $^V; # fine
>> my $x = !$^V; # bad
>> if ($^V) { } # bad
>>
>> -- Matthew Horsfall (alh)
>
>
>
> Duane Bronson
> [email protected] <mailto:[email protected]>
> http://www.nerdlogic.com/ <http://www.nerdlogic.com/>
> 5 Goden St.
> Belmont, MA 02478
> 617.515.2909
>
>
>
>
>
Duane Bronson
[email protected] <mailto:[email protected]>
http://www.nerdlogic.com/ <http://www.nerdlogic.com/>
5 Goden St.
Belmont, MA 02478
617.515.2909