This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In newATTRSUB, clear glob slot before lowering refcount.
[perl5.git] / t / op / sub.t
index ec8e211..06b8d07 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan( tests => 32 );
+plan( tests => 33 );
 
 sub empty_sub {}
 
@@ -200,3 +200,18 @@ ok !exists $INC{"re.pm"}, 're.pm not loaded yet';
     is $str[1], $str[0],
       'XSUB clobbering sub whose DESTROY assigns to the glob';
 }
+{
+    no warnings 'redefine';
+    sub foo {}
+    bless \&foo, 'newATTRSUBbug';
+    sub newATTRSUBbug::DESTROY {
+        my $str1 = "$_[0]";
+        *foo = sub{}; # GvSV had no refcount, so this freed it
+        my $str2 = "$_[0]";   # used to be UNKNOWN(0x7fdda29310e0)
+        @str = ($str1, $str2);
+    }
+    splice @str;
+    eval "sub foo{}";
+    is $str[1], $str[0],
+      'Pure-Perl sub clobbering sub whose DESTROY assigns to the glob';
+}