]> git.vpit.fr Git - perl/modules/Variable-Magic.git/commitdiff
Stop leaking objects stored in the data slot
authorVincent Pit <vince@profvince.com>
Mon, 30 Nov 2009 20:18:23 +0000 (21:18 +0100)
committerVincent Pit <vince@profvince.com>
Mon, 30 Nov 2009 20:18:23 +0000 (21:18 +0100)
MANIFEST
Magic.xs
t/80-leaks.t [new file with mode: 0644]

index d4d24e855e09d4d7871e11661266cdd1d4f4e75f..88af47ae4241b7be8135b4b0092affced3561af5 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -37,6 +37,7 @@ t/34-glob.t
 t/35-stash.t
 t/40-threads.t
 t/41-clone.t
+t/80-leaks.t
 t/91-pod.t
 t/92-pod-coverage.t
 t/95-portability-files.t
index 6ec752bcf14a3f5565b7a5372c5bb91bfa021a71..df86b33edfd7ee6dd994d48b6d87721fbac39800 100644 (file)
--- a/Magic.xs
+++ b/Magic.xs
@@ -681,6 +681,7 @@ STATIC UV vmg_cast(pTHX_ SV *sv, const SV *wiz, SV **args, I32 items) {
 
  data = (w->cb_data) ? vmg_data_new(w->cb_data, sv, args, items) : NULL;
  mg = sv_magicext(sv, data, PERL_MAGIC_ext, w->vtbl, (const char *) wiz, HEf_SVKEY);
+ SvREFCNT_dec(data);
  mg->mg_private = SIG_WIZ;
 #if MGf_COPY
  if (w->cb_copy)
diff --git a/t/80-leaks.t b/t/80-leaks.t
new file mode 100644 (file)
index 0000000..dcaf66a
--- /dev/null
@@ -0,0 +1,40 @@
+#!perl -T
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+
+use Variable::Magic qw/wizard cast/;
+
+our $destroyed;
+
+{
+ package Variable::Magic::TestDestructor;
+
+ sub new { bless { }, shift }
+
+ sub DESTROY { ++$::destroyed }
+}
+
+sub D () { 'Variable::Magic::TestDestructor' }
+
+{
+ local $destroyed = 0;
+
+ my $w = wizard data => sub { $_[1] };
+
+ {
+  my $obj = D->new;
+
+  {
+   my $x = 1;
+   cast $x, $w, $obj;
+   is $destroyed, 0;
+  }
+
+  is $destroyed, 0;
+ }
+
+ is $destroyed, 1;
+}