From: Tony Cook Date: Sat, 10 Mar 2007 23:03:37 +0000 (+0000) Subject: the OUTPUT typemap entry for the Imager type was adding an extra X-Git-Tag: Imager-0.56~15 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/b340c6293b085670bfcd455ecda0d471e8e81b02?ds=inline the OUTPUT typemap entry for the Imager type was adding an extra reference to the wrapper object, causing the objects to leak. RT #24992 --- diff --git a/t/t82inline.t b/t/t82inline.t index 3ab09af5..55b44494 100644 --- a/t/t82inline.t +++ b/t/t82inline.t @@ -10,7 +10,7 @@ use Cwd 'getcwd'; plan skip_all => "Inline won't work in directories with spaces" if getcwd() =~ / /; -plan tests => 8; +plan tests => 9; require Inline; Inline->import(with => 'Imager'); @@ -244,3 +244,16 @@ my $im3 = do_lots($im2); ok($im3, "do_lots()") or print "# ", Imager->_error_as_msg, "\n"; ok($im3->write(file=>'testout/t82lots.ppm'), "write t82lots.ppm"); + +{ # RT #24992 + # the T_IMAGER_FULL_IMAGE typemap entry was returning a blessed + # hash with an extra ref, causing memory leaks + + my $im = make_10x10(); + my $im2 = Imager->new(xsize => 10, ysize => 10); + use B; + my $imb = B::svref_2object($im); + my $im2b = B::svref_2object($im2); + is ($imb->REFCNT, $im2b->REFCNT, + "check refcnt of imager object hash between normal and typemap generated"); +} diff --git a/typemap b/typemap index abc867e9..4438d086 100644 --- a/typemap +++ b/typemap @@ -111,7 +111,7 @@ T_IMAGER_FULL_IMAGE HV *hv = newHV(); sv_setref_pv(imobj, \"Imager::ImgRaw\", $var); hv_store(hv, "IMG", 3, imobj, 0); - $arg = sv_2mortal(sv_bless(newRV((SV*)hv), gv_stashpv("Imager", 1))); + $arg = sv_2mortal(sv_bless(newRV_noinc((SV*)hv), gv_stashpv("Imager", 1))); } else { $arg = &PL_sv_undef;