This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make RC-stack-aware: S_fold_constants()
authorDavid Mitchell <davem@iabyn.com>
Thu, 5 Jan 2023 11:37:23 +0000 (11:37 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 16 Aug 2023 16:16:59 +0000 (17:16 +0100)
The folded SV it pops off the stack should be treated as
reference counted.

op.c

diff --git a/op.c b/op.c
index e672b16..37eb058 100644 (file)
--- a/op.c
+++ b/op.c
@@ -4969,7 +4969,11 @@ S_fold_constants(pTHX_ OP *const o)
 
     switch (ret) {
     case 0:
-        sv = *(PL_stack_sp--);
+        sv = *PL_stack_sp;
+        if (rpp_stack_is_rc())
+            SvREFCNT_dec(sv);
+        PL_stack_sp--;
+
         if (o->op_targ && sv == PAD_SV(o->op_targ)) {  /* grab pad temp? */
             pad_swipe(o->op_targ,  FALSE);
         }