This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
goto.t: add freeing CV test
authorDavid Mitchell <davem@iabyn.com>
Thu, 9 Jul 2015 08:22:38 +0000 (09:22 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Feb 2016 08:59:35 +0000 (08:59 +0000)
This code SEGVed in a cpan/ module while I was messing with pp_goto.
Add it to t/op/goto.t so that it can SEGV there instead.

t/op/goto.t

index 73a6b95..aa2f24f 100644 (file)
@@ -10,7 +10,7 @@ BEGIN {
 
 use warnings;
 use strict;
-plan tests => 97;
+plan tests => 98;
 our $TODO;
 
 my $deprecated = 0;
@@ -239,6 +239,22 @@ package Do_undef {
     ::is($count, 10, "goto undef_sub safe");
 }
 
+# make sure that nothing nasty happens if the old CV is freed while
+# goto'ing
+
+package Free_cv {
+    my $results;
+    sub f {
+        no warnings 'redefine';
+        *f = sub {};
+        goto &g;
+    }
+    sub g { $results = "(@_)" }
+
+    f(1,2,3);
+    ::is($results, "(1 2 3)", "Free_cv");
+}
+
 
 # bug #22181 - this used to coredump or make $x undefined, due to
 # erroneous popping of the inner BLOCK context