Re: [perl #15523] Memory Leak in split with trailing empty elements
Slaven Rezic [Wed, 31 Jul 2002 09:50:06 +0000 (11:50 +0200)]
Message-id: <87ado85ob5.fsf@vran.herceg.de>

p4raw-id: //depot/perl@17696

pp.c

diff --git a/pp.c b/pp.c
index 7fa9c06..d7fc6bf 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -4611,8 +4611,12 @@ PP(pp_split)
        iters++;
     }
     else if (!origlimit) {
-       while (iters > 0 && (!TOPs || !SvANY(TOPs) || SvCUR(TOPs) == 0))
-           iters--, SP--;
+       while (iters > 0 && (!TOPs || !SvANY(TOPs) || SvCUR(TOPs) == 0)) {
+           if (TOPs && !make_mortal)
+               sv_2mortal(TOPs);
+           iters--;
+           SP--;
+       }
     }
 
     if (realarray) {