Skip Menu |

This queue is for tickets about the Test-Weaken CPAN distribution.

Report information
The Basics
Id: 48125
Status: resolved
Priority: 0/
Queue: Test-Weaken

People
Owner: jkegl [...] cpan.org
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 3.001_000
Fixed in: (no value)



Subject: substr lvalue held on scratchpad (affecting DBI)
Date: Fri, 24 Jul 2009 06:25:14 +1000
To: bug-Test-Weaken [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
With Test::Weaken 3.001_000 and recent i386 debian perl 5.10.0 the program below reports a leak $VAR1 = bless( { 'unfreed_probes' => [ \'Hello There' ], 'weak_probe_count' => 0, 'test' => 1, 'constructor' => sub { "DUMMY" }, 'strong_probe_count' => 2, 'probe_count' => 2 }, 'Test::Weaken' ); Some poking around suggests it's a real leak, that the use of lvalue substr() on a lexical in a function somehow keeps that scalar alive in the function's scratchpad until the next call to that function. Assuming this is not a bug in perl it'd be worth a note in the tips and techniques section of the Test::Weaken docs. Perhaps with suggestions for calling again through offending functions to reset the scratch, or whatever. Alternately in the future maybe some strategic code in Test::Weaken could help detect a scratchpad scalar (from its flags) and tolerate one leftover reference on it. I struck this in recent DBI 1.609 where its _new_dbh() and _new_sth() functions do such an lvalue substr assignment. Test::Weaken 3.001 applied to a dbh or sth object reports string scalars "DBI::SQLite::db" and "DBI::SQLite::st" as unfreed. This only arises with Test::Weaken 3.001 since only it descends into tie objects, which is where these bits are held in DBI. I believe the problem is nothing to do with ties though (as the program below shows), merely that new descending has reached something that was always dodgy!
use strict; use warnings; use Test::Weaken; my $leaks = Test::Weaken::leaks (sub { my $str = 'Hello World'; substr($str,-5,5) = 'There'; return \$str; }); if (! $leaks) { print "no leaks\n"; } else { require Data::Dumper; print Data::Dumper::Dumper($leaks); }
A documentation fix. Added to the end of the wishlist. Kevin, are you considering filing this as a Perl bug?
Subject: Re: [rt.cpan.org #48125] substr lvalue held on scratchpad (affecting DBI)
Date: Fri, 24 Jul 2009 07:07:28 +1000
To: bug-Test-Weaken [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Jeffrey Kegler via RT" <bug-Test-Weaken@rt.cpan.org> writes: Show quoted text
> > Kevin, are you considering filing this as a Perl bug?
I don't know if it's a bug or a feature. :-) Do you know a friendly expert who could say?
Subject: Re: [rt.cpan.org #48125] substr lvalue held on scratchpad (affecting DBI)
Date: Fri, 24 Jul 2009 10:18:40 +1000
To: bug-Test-Weaken [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
I sent a perlbug report anyway, since if nothing else I couldn't find anything in the docs to explain what could be happening.
Stalled, because it's in the "To Do" queue, and because I'd like to see how the perlbug turns out.
Subject: Re: [rt.cpan.org #48125] substr lvalue held on scratchpad (affecting DBI)
Date: Sun, 02 Aug 2009 09:37:50 +1000
To: bug-Test-Weaken [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Jeffrey Kegler via RT" <bug-Test-Weaken@rt.cpan.org> writes: Show quoted text
> > see how the perlbug turns out.
Sounds very like a perl bug ... another victory for test::weaken against leaks and semi-leaks :-). My workaround is to open another dummy dbh and sth handle, which flushes the scratchpads of the ones I care about. I tried detecting the offending scalars from their content, but looking into the value seemed to make the leaking even worse! (Incidentally, DBI::dr "driver objects" are permanent global singleton thingies. The "ignore" option covers them, but you could bear them in mind for possible automatic ignoring in the distant future.)
Kevin -- let me know if the bug is accepted. I may brag on it in perlmonks or elsewhere. Also, my "SEE ALSO" section may now be unduly humble. :-) The language there dates from Test::Weaken's alpha phase. Presumably you have reasons for using Test::Weaken instead of Test::Memory::Cycle and Devel::Cycle. What are the factors that make you prefer Test::Weaken?
Subject: Re: [rt.cpan.org #48125] substr lvalue held on scratchpad (affecting DBI)
Date: Thu, 06 Aug 2009 07:46:03 +1000
To: bug-Test-Weaken [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Jeffrey Kegler via RT" <bug-Test-Weaken@rt.cpan.org> writes: Show quoted text
> > Also, my "SEE ALSO" section may now be unduly humble. :-)
As to me? Just maybe "some ideas and patches" is plenty for me. Show quoted text
> Presumably you have > reasons for using Test::Weaken instead of Test::Memory::Cycle and > Devel::Cycle. What are the factors that make you prefer Test::Weaken?
I started with my own weaken() and then went to "why can't someone else do it?" :-), especially for making sure sub-objects are destroyed too. This was with gtk widgets. The cycles that prevent freeing are often from userdata in signal callbacks, and that data is not directly in the object's hash, so I suspect the two cycle modules won't see it. I also thought I wanted a direct weaken gives destroy check. (I'm vaguely contemplating whether that userdata could be recorded in a more visible place. Test::Weaken might then check it's released, the cycle modules could diagnose it, and Devel::FindRef would find it ...)
Stalled, waiting in the "TO DO" queue. Also probably want to see the result of the perl bug report first.
Subject: Re: [rt.cpan.org #48125] substr lvalue held on scratchpad (affecting DBI)
Date: Sat, 12 Dec 2009 07:22:00 +1100
To: bug-Test-Weaken [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Jeffrey Kegler via RT" <bug-Test-Weaken@rt.cpan.org> writes: Show quoted text
> > let me know if the bug is accepted
For a plain local variable - not really. It holds onto space which you might have thought would be released, but that's about the worst of it, and happens all the time behind the scenes anyway. For a tied or magical "my" local variable - yes, a bug. The variable doesn't get untied at the end of scope and its destructor doesn't run. It's not an outright leak, because the next call to the function destructs the previous value, but that's much later than it's supposed to be -- if I understand it all correctly. (Details at http://rt.perl.org/rt3/Public/Bug/Display.html?id=67838 )
Fascinating. Thanks for the work on this. Re lack of any progress on the Test::Weaken wishlist. I decided I need to make progress on Marpa, and that nothing less than 100% focus would do it. Marpa is soon to be documented & to leave experimental mode & to go into alpha. But I expect to remain focused on Marpa for a few months more. My apologies. On Fri Dec 11 15:22:52 2009, user42@zip.com.au wrote: Show quoted text
> "Jeffrey Kegler via RT" <bug-Test-Weaken@rt.cpan.org> writes:
> > > > let me know if the bug is accepted
> > For a plain local variable - not really. It holds onto space which you > might have thought would be released, but that's about the worst of it, > and happens all the time behind the scenes anyway. > > For a tied or magical "my" local variable - yes, a bug. The variable > doesn't get untied at the end of scope and its destructor doesn't run. > > It's not an outright leak, because the next call to the function > destructs the previous value, but that's much later than it's supposed > to be -- if I understand it all correctly. > > > (Details at http://rt.perl.org/rt3/Public/Bug/Display.html?id=67838 )
Subject: Re: [rt.cpan.org #48125] substr lvalue held on scratchpad (affecting DBI)
Date: Sat, 12 Dec 2009 09:34:31 +1100
To: bug-Test-Weaken [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Jeffrey Kegler via RT" <bug-Test-Weaken@rt.cpan.org> writes: Show quoted text
> > Marpa
I think I saw some of that while nosing around your code, it looks pretty likely. I gave Test::Synopsis a try recently, which may be slightly similar, but doing less.
The perlbug was http://rt.perl.org/rt3/Public/ Bug/Display.html?id=67838 Now that that is resolved, I am closing this ticket as well.