This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make POPEVAL safe against re-entrancy
authorDavid Mitchell <davem@iabyn.com>
Mon, 19 Oct 2015 15:46:06 +0000 (16:46 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Feb 2016 09:18:30 +0000 (09:18 +0000)
cop.h

diff --git a/cop.h b/cop.h
index d0146ce..09fd2a6 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -755,12 +755,17 @@ struct block_eval {
 
 #define POPEVAL(cx)                                                    \
     STMT_START {                                                       \
+        SV *sv;                                                         \
        PL_in_eval = CxOLD_IN_EVAL(cx);                                 \
        PL_eval_root = cx->blk_eval.old_eval_root;                      \
-       if (cx->blk_eval.cur_text && SvSCREAM(cx->blk_eval.cur_text))   \
-           SvREFCNT_dec_NN(cx->blk_eval.cur_text);                     \
-       if (cx->blk_eval.old_namesv)                                    \
-           sv_2mortal(cx->blk_eval.old_namesv);                        \
+       sv = cx->blk_eval.cur_text;                                     \
+       if (sv && SvSCREAM(sv)) {                                       \
+           cx->blk_eval.cur_text = NULL;                               \
+           SvREFCNT_dec_NN(sv);                                        \
+        }                                                               \
+       sv = cx->blk_eval.old_namesv;                                   \
+       if (sv && !SvTEMP(sv))/* TEMP => POPEVAL re-entrantly called */ \
+           sv_2mortal(sv);                                             \
     } STMT_END
 
 /* loop context */