Subject: | $op->sv memory leak introduced by B::Generate |
Date: | Thu, 19 Jun 2008 15:48:47 +0200 |
To: | bug-B-Generate [...] rt.cpan.org |
From: | Anton Berezin <tobez [...] tobez.org> |
Hi,
Consider the following little test case:
----------8<-----------8<-----------8<-----------8<-----------8<------
#! /usr/bin/perl
use warnings;
use strict;
use Devel::Leak;
use B;
use B::Generate;
my $h;
print "0: ", Devel::Leak::NoteSV($h), "\n";
cc();
print "1: ", Devel::Leak::NoteSV($h), "\n";
cc();
print "2: ", Devel::Leak::NoteSV($h), "\n";
cc();
print "3: ", Devel::Leak::NoteSV($h), "\n";
sub cc {
check(sub { return "heps" . $_[0] . "be" . $_[1] . "4" });
}
sub check
{
my ($sub) = @_;
my $root = B::svref_2object($sub);
$root = $root->ROOT;
my @op = get_all_children($root);
for my $op (@op) {
if ($op->can("sv")) {
my $sv = $op->sv;
}
}
}
sub get_all_children
{
my ($op) = @_;
my @op;
if ($op->can("first")) {
push @op, $op->first, get_all_children($op->first);
}
if ($op->can("sibling")) {
push @op, $op->sibling, get_all_children($op->sibling);
}
@op;
}
----------8<-----------8<-----------8<-----------8<-----------8<------
On my machine, running this produces
0: 6517
1: 6874
2: 6879
3: 6884
If I comment out the "use B::Generate" statement above, the same code
produces
0: 5976
1: 6328
2: 6328
3: 6328
So there is a leak somewhere in the B::Generate's version of $op->sv.
Unfortunately, I lack the knowledge of perl guts to come up with a patch,
but I do hope it is addressed.
Thanks for the module,
Cheers,
\Anton.
--
We're going for 'working' here. 'clean' is for people with skills...
-- Flemming Jacobsen