ithreads: SVs that were only on the tmps stack leaked
Dave Mitchell [Tue, 3 Jan 2006 02:20:28 +0000 (02:20 +0000)]
p4raw-id: //depot/perl@26591

sv.c

diff --git a/sv.c b/sv.c
index 9cc9c37..d32bd99 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -10767,6 +10767,20 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
     else {
        init_stacks();
        ENTER;                  /* perl_destruct() wants to LEAVE; */
+
+       /* although we're not duplicating the tmps stack, we should still
+        * add entries for any SVs on the tmps stack that got cloned by a
+        * non-refcount means (eg a temp in @_); otherwise they will be
+        * orphaned
+        */
+       for (i = 0; i<= proto_perl->Ttmps_ix; i++) {
+           SV *nsv = (SV*)ptr_table_fetch(PL_ptr_table,
+                   proto_perl->Ttmps_stack[i]);
+           if (nsv && !SvREFCNT(nsv)) {
+               EXTEND_MORTAL(1);
+               PL_tmps_stack[++PL_tmps_ix] = SvREFCNT_inc(nsv);
+           }
+       }
     }
 
     PL_start_env       = proto_perl->Tstart_env;       /* XXXXXX */