Skip Menu |

This queue is for tickets about the B-Generate CPAN distribution.

Report information
The Basics
Id: 36845
Status: resolved
Priority: 0/
Queue: B-Generate

People
Owner: Nobody in particular
Requestors: GRUBER [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.11
Fixed in: (no value)



Subject: $op->sv memory leak introduced by B::Generate
[I apologize if I report it twice, it does not look like the E-mail report went anywhere] 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. The leak present at least in 1.11 and 1.12_06 tested on perl 5.8.8 on several FreeBSD and Linux boxes. Thanks for the module, Cheers, \Anton.
Ok, the patch is attached.
--- lib/B/Generate.xs 2008-02-24 07:19:33.000000000 +0100 +++ /home/tobez/_/Generate.xs 2008-06-25 19:11:45.000000000 +0200 @@ -123,6 +123,7 @@ find_cv_by_root(OP* o) { cached = hv_fetch_ent(root_cache, key, 0, 0); if(cached) { + SvREFCNT_dec(key); return HeVAL(cached); } @@ -176,6 +177,7 @@ find_cv_by_root(OP* o) { cached = hv_store_ent(root_cache, key, newRV((SV*)cv), 0); } + SvREFCNT_dec(key); return (SV*) HeVAL(cached); }
Resolved in 1.12_07.