Subject: | false positive on unfilled array |
Date: | Sun, 14 Jun 2009 08:19:25 +1000 |
To: | bug-Test-Weaken [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
With Test::Weaken 2.003_001 and recent debian i386 perl 5.10.0, a
non-existant element in an array causes an unfreed_proberef to be
returned. Sample failing test script and possible change below.
(I noticed this with some of my code that has such part-filled arrays.
It was ok with 2.002.)
--- Weaken.pm.orig 2009-06-13 18:30:23.000000000 +1000
+++ Weaken.pm 2009-06-13 18:39:19.000000000 +1000
@@ -88,7 +88,11 @@
FIND_CHILDREN: {
if ( $object_type eq 'ARRAY' ) {
- @child_probes = map { \$_ } @{$follow_probe};
+ foreach my $i (0 .. $#$follow_probe) {
+ if (exists $follow_probe->[$i]) {
+ push @child_probes, \$follow_probe->[$i];
+ }
+ }
last FIND_CHILDREN;
}
#!/usr/bin/perl
package main;
use strict;
use warnings;
use Test::Weaken;
use Test::More tests => 4;
{
my $leaks = Test::Weaken::leaks(sub {
my @array;
$#array = 1;
return \@array;
});
ok(!$leaks, 'pre-extended array');
}
{
my $leaks = Test::Weaken::leaks(sub {
my @array = (123, 456);
delete $array[0];
return \@array;
});
ok(!$leaks, 'array element delete()');
}
{
my @global;
$#global = 1;
my $leaks = Test::Weaken::leaks(sub {
return \@global;
});
ok(! exists $global[0],
"leaks doesn't bring global[0] into existance");
ok(! exists $global[1],
"leaks doesn't bring global[1] into existance");
}
exit 0;