From: Jesse Luehrs Date: Sat, 13 Nov 2010 17:08:50 +0000 (-0600) Subject: don't leak old glob values X-Git-Tag: 0.14~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=12134e83d1a206c1305977bf3d986f2d91aa85a2;p=gitmo%2FPackage-Stash-XS.git don't leak old glob values --- diff --git a/Stash.xs b/Stash.xs index 17b9c64..4161ac6 100644 --- a/Stash.xs +++ b/Stash.xs @@ -389,18 +389,28 @@ add_package_symbol(self, variable, initial=NULL, ...) switch (variable.type) { case VAR_SCALAR: + if (GvSV(glob)) + SvREFCNT_dec(GvSV(glob)); GvSV(glob) = val; break; case VAR_ARRAY: + if (GvAV(glob)) + SvREFCNT_dec((SV*)GvAV(glob)); GvAV(glob) = (AV*)val; break; case VAR_HASH: + if (GvHV(glob)) + SvREFCNT_dec((SV*)GvHV(glob)); GvHV(glob) = (HV*)val; break; case VAR_CODE: + if (GvCV(glob)) + SvREFCNT_dec((SV*)GvCV(glob)); GvCV(glob) = (CV*)val; break; case VAR_IO: + if (GvIO(glob)) + SvREFCNT_dec((SV*)GvIO(glob)); GvIOp(glob) = (IO*)val; break; } diff --git a/t/20-leaks.t b/t/20-leaks.t index bdfd37a..53989a6 100644 --- a/t/20-leaks.t +++ b/t/20-leaks.t @@ -62,7 +62,6 @@ use Symbol; $foo->add_package_symbol('$scalar_init' => 1); $foo->add_package_symbol('@array_init' => []); $foo->add_package_symbol('%hash_init' => {}); - # hmmm, wonder why this coderef isn't treated as a leak $foo->add_package_symbol('&code_init' => sub { "foo" }); $foo->add_package_symbol('io_init' => Symbol::geniosym); } "add_package_symbol doesn't leak";