This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [PATCH scope.c] Re: local($tied->{foo}) leaks
authorDave Mitchell <davem@fdisolutions.com>
Wed, 8 May 2002 00:11:02 +0000 (01:11 +0100)
committerJarkko Hietaniemi <jhi@iki.fi>
Tue, 7 May 2002 22:24:59 +0000 (22:24 +0000)
Message-ID: <20020508001102.D4118@fdgroup.com>

p4raw-id: //depot/perl@16456

pp_hot.c
scope.c

index 98229a2..de2dec4 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1699,17 +1699,8 @@ PP(pp_helem)
                    STRLEN keylen;
                    char *key = SvPV(keysv, keylen);
                    SAVEDELETE(hv, savepvn(key,keylen), keylen);
                    STRLEN keylen;
                    char *key = SvPV(keysv, keylen);
                    SAVEDELETE(hv, savepvn(key,keylen), keylen);
-               } else {
-                   SV *sv;
+               } else
                    save_helem(hv, keysv, svp);
                    save_helem(hv, keysv, svp);
-                   sv = *svp;
-                   /* If we're localizing a tied hash element, this new
-                    * sv won't actually be stored in the hash - so it
-                    * won't get reaped when the localize ends. Ensure it
-                    * gets reaped by mortifying it instead. DAPM */
-                   if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
-                       sv_2mortal(sv);
-               }
             }
        }
        else if (PL_op->op_private & OPpDEREF)
             }
        }
        else if (PL_op->op_private & OPpDEREF)
@@ -2964,17 +2955,8 @@ PP(pp_aelem)
            PUSHs(lv);
            RETURN;
        }
            PUSHs(lv);
            RETURN;
        }
-       if (PL_op->op_private & OPpLVAL_INTRO) {
-           SV *sv;
+       if (PL_op->op_private & OPpLVAL_INTRO)
            save_aelem(av, elem, svp);
            save_aelem(av, elem, svp);
-           sv = *svp;
-           /* If we're localizing a tied array element, this new sv
-            * won't actually be stored in the array - so it won't get
-            * reaped when the localize ends. Ensure it gets reaped by
-            * mortifying it instead. DAPM */
-           if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
-               sv_2mortal(sv);
-       }
        else if (PL_op->op_private & OPpDEREF)
            vivify_ref(*svp, PL_op->op_private & OPpDEREF);
     }
        else if (PL_op->op_private & OPpDEREF)
            vivify_ref(*svp, PL_op->op_private & OPpDEREF);
     }
diff --git a/scope.c b/scope.c
index 85a0680..a1fdfd1 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -587,23 +587,39 @@ Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p)
 void
 Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr)
 {
 void
 Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr)
 {
+    SV *sv;
     SSCHECK(4);
     SSPUSHPTR(SvREFCNT_inc(av));
     SSPUSHINT(idx);
     SSPUSHPTR(SvREFCNT_inc(*sptr));
     SSPUSHINT(SAVEt_AELEM);
     save_scalar_at(sptr);
     SSCHECK(4);
     SSPUSHPTR(SvREFCNT_inc(av));
     SSPUSHINT(idx);
     SSPUSHPTR(SvREFCNT_inc(*sptr));
     SSPUSHINT(SAVEt_AELEM);
     save_scalar_at(sptr);
+    sv = *sptr;
+    /* If we're localizing a tied array element, this new sv
+     * won't actually be stored in the array - so it won't get
+     * reaped when the localize ends. Ensure it gets reaped by
+     * mortifying it instead. DAPM */
+    if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
+       sv_2mortal(sv);
 }
 
 void
 Perl_save_helem(pTHX_ HV *hv, SV *key, SV **sptr)
 {
 }
 
 void
 Perl_save_helem(pTHX_ HV *hv, SV *key, SV **sptr)
 {
+    SV *sv;
     SSCHECK(4);
     SSPUSHPTR(SvREFCNT_inc(hv));
     SSPUSHPTR(SvREFCNT_inc(key));
     SSPUSHPTR(SvREFCNT_inc(*sptr));
     SSPUSHINT(SAVEt_HELEM);
     save_scalar_at(sptr);
     SSCHECK(4);
     SSPUSHPTR(SvREFCNT_inc(hv));
     SSPUSHPTR(SvREFCNT_inc(key));
     SSPUSHPTR(SvREFCNT_inc(*sptr));
     SSPUSHINT(SAVEt_HELEM);
     save_scalar_at(sptr);
+    sv = *sptr;
+    /* If we're localizing a tied hash element, this new sv
+     * won't actually be stored in the hash - so it won't get
+     * reaped when the localize ends. Ensure it gets reaped by
+     * mortifying it instead. DAPM */
+    if (SvTIED_mg(sv, PERL_MAGIC_tiedelem))
+       sv_2mortal(sv);
 }
 
 void
 }
 
 void