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

diff --git a/cop.h b/cop.h
index d95c799..4eefc4c 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -1026,9 +1026,14 @@ struct subst {
         SvREFCNT_inc_void_NN(targ)
 
 #  define POPSUBST(cx) \
+    STMT_START {                                                       \
+        REGEXP *re;                                                     \
        rxres_free(&cx->sb_rxres);                                      \
-       ReREFCNT_dec(cx->sb_rx);                                        \
-        SvREFCNT_dec_NN(cx->sb_targ)
+       re = cx->sb_rx;                                                 \
+       cx->sb_rx = NULL;                                               \
+       ReREFCNT_dec(re);                                               \
+        SvREFCNT_dec_NN(cx->sb_targ);                                   \
+    } STMT_END
 #endif
 
 #define CxONCE(cx)             ((cx)->cx_type & CXp_ONCE)