This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [perl #23265] Nested anonymous subs
authorDave Mitchell <davem@fdisolutions.com>
Sun, 10 Aug 2003 01:35:30 +0000 (02:35 +0100)
committerJarkko Hietaniemi <jhi@iki.fi>
Sun, 10 Aug 2003 17:55:03 +0000 (17:55 +0000)
Message-ID: <20030810003530.GB6547@fdgroup.com>

p4raw-id: //depot/perl@20597

pad.c
t/op/closure.t

diff --git a/pad.c b/pad.c
index 90d9979..a121e53 100644 (file)
--- a/pad.c
+++ b/pad.c
@@ -258,9 +258,15 @@ Perl_pad_undef(pTHX_ CV* cv)
                {
                    assert(CvWEAKOUTSIDE(innercv));
                    CvWEAKOUTSIDE_off(innercv);
-                   CvOUTSIDE(innercv) = outercv;
                    CvOUTSIDE_SEQ(innercv) = seq;
-                   SvREFCNT_inc(outercv);
+                   /* don't relink to grandfather if he's being freed */
+                   if (SvREFCNT(outercv)) {
+                       CvOUTSIDE(innercv) = outercv;
+                       SvREFCNT_inc(outercv);
+                   }
+                   else {
+                       CvOUTSIDE(innercv) = Nullcv;
+                   }
                }
            }
        }
index dd7b50c..763e2a7 100755 (executable)
@@ -13,7 +13,7 @@ BEGIN {
 
 use Config;
 
-print "1..184\n";
+print "1..185\n";
 
 my $test = 1;
 sub test (&) {
@@ -641,4 +641,27 @@ f16302();
     test { $a{7}->()->() + $a{11}->()->() == 18 };
 }
 
+# bugid #23265 - this used to coredump during destruction of PL_maincv
+# and its children
+
+require './test.pl';
+
+my $got = runperl(
+    prog => q[
+       print
+           sub {$_[0]->(@_)} -> (
+               sub {
+                   $_[1]
+                       ?  $_[0]->($_[0], $_[1] - 1) .  sub {"x"}->()
+                       : "y"
+               },   
+               2
+           )
+           , "\n"
+       ;            
+    
+    ],
+    stderr => 1
+);
+test { $got eq "yxx\n" };