]> git.imager.perl.org - imager.git/commitdiff
the OUTPUT typemap entry for the Imager type was adding an extra
authorTony Cook <tony@develop=help.com>
Sat, 10 Mar 2007 23:03:37 +0000 (23:03 +0000)
committerTony Cook <tony@develop=help.com>
Sat, 10 Mar 2007 23:03:37 +0000 (23:03 +0000)
reference to the wrapper object, causing the objects to leak.

RT #24992

t/t82inline.t
typemap

index 3ab09af5bfea2c47a7b25531745f4e9bcb96928b..55b44494ba08324a3b73abee8e8660d1d7e9e5e2 100644 (file)
@@ -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 abc867e97654e4edfe680a473579f7ac480bc5a8..4438d086a17cf804b46bc949d57920e58a0d260e 100644 (file)
--- 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;