]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/41-clone.t
Fix leaks of cloned coderefs that access lexicals
[perl/modules/Variable-Magic.git] / t / 41-clone.t
index 032fa92d3b85e8072406322700b9e7e5e211a457..c3c48223ed666c5d9760cb109ff186f8c3133ddd 100644 (file)
@@ -22,16 +22,21 @@ use Variable::Magic qw/wizard cast dispell getdata getsig VMG_THREADSAFE/;
 
 if (VMG_THREADSAFE) {
  plan tests => 3 + 2 * (2 * 8 + 2) + 2 * (2 * 5 + 2);
- diag 'This will leak a few scalars';
+ my $v = $threads::VERSION;
+ diag "Using threads $v" if defined $v;
+ $v = $threads::shared::VERSION;
+ diag "Using threads::shared $v" if defined $v;
 } else {
  plan skip_all => 'This Variable::Magic isn\'t thread safe';
 }
 
 my $destroyed : shared = 0;
 my $c         : shared = 0;
-my $wiz = wizard get  => sub { ++$c },
-                 data => sub { $_[1] + threads->tid() },
-                 free => sub { ++$destroyed };
+my $wiz = eval {
+ wizard get  => sub { ++$c },
+        data => sub { $_[1] + threads->tid() },
+        free => sub { ++$destroyed }
+};
 is($@,     '',    "wizard in main thread doesn't croak");
 isnt($wiz, undef, "wizard in main thread is defined");
 is($c,     0,     "wizard in main thread doesn't trigger magic");