Re: [Boston.pm] perl 5.10 memory leak?

2016-12-14 Thread Duane Bronson
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  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  > wrote:
> Ahh - the bug is in 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) > > wrote:
>> 
>> On Wed, Dec 14, 2016 at 12:55 AM, Matthew Horsfall (alh)
>> > wrote:
>>> On Tue, Dec 13, 2016 at 6:41 PM, Ben Tilly >> > 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
> nerdmach...@gmail.com 
> http://www.nerdlogic.com/ 
> 5 Goden St.
> Belmont, MA 02478
> 617.515.2909
> 
> 
> 
> 
> 



Duane Bronson
nerdmach...@gmail.com 
http://www.nerdlogic.com/ 
5 Goden St.
Belmont, MA 02478
617.515.2909





___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm


Re: [Boston.pm] perl 5.10 memory leak?

2016-12-14 Thread Matthew Horsfall (alh)
On Wed, Dec 14, 2016 at 10:44 AM, Duane Bronson  wrote:
> Ahh - the bug is in 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.

I manually tested the leak with versions of Perl I have installed
until I got it down to between two and then looked at the git log
between those two versions for $^V :)

-- Matthew Horsfall (alh)

___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm


Re: [Boston.pm] perl 5.10 memory leak?

2016-12-14 Thread Ben Tilly
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 
wrote:

> Ahh - the bug is in 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) 
> wrote:
>
> On Wed, Dec 14, 2016 at 12:55 AM, Matthew Horsfall (alh)
>  wrote:
>
> On Tue, Dec 13, 2016 at 6:41 PM, Ben Tilly  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*
> nerdmach...@gmail.com
> http://www.nerdlogic.com/
> 5 Goden St.
> Belmont, MA 02478
> 617.515.2909
>
>
>
>
>

___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm


Re: [Boston.pm] perl 5.10 memory leak?

2016-12-14 Thread Duane Bronson
Ahh - the bug is in 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)  
> wrote:
> 
> On Wed, Dec 14, 2016 at 12:55 AM, Matthew Horsfall (alh)
>  wrote:
>> On Tue, Dec 13, 2016 at 6:41 PM, Ben Tilly  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
nerdmach...@gmail.com 
http://www.nerdlogic.com/ 
5 Goden St.
Belmont, MA 02478
617.515.2909





___
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm