This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_split: add TonyC's stack-not-refcounted-suggestion and tests
[perl5.git] / pp.c
diff --git a/pp.c b/pp.c
index ce16c56..5b5e163 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -6034,6 +6034,9 @@ PP(pp_split)
             oldsave = PL_savestack_ix;
         }
 
+       /* Some defence against stack-not-refcounted bugs */
+       (void)sv_2mortal(SvREFCNT_inc_simple_NN(ary));
+
        if ((mg = SvTIED_mg((const SV *)ary, PERL_MAGIC_tied))) {
            PUSHMARK(SP);
            XPUSHs(SvTIED_obj(MUTABLE_SV(ary), mg));
@@ -6356,7 +6359,7 @@ PP(pp_split)
     }
 
     PUTBACK;
-    LEAVE_SCOPE(oldsave); /* may undo an earlier SWITCHSTACK */
+    LEAVE_SCOPE(oldsave);
     SPAGAIN;
     if (realarray) {
         if (!mg) {