From: Dave Mitchell Date: Fri, 3 May 2002 23:51:10 +0000 (+0100) Subject: Re: [PATCH scope.c] Re: local($tied->{foo}) leaks X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b412ba13de1aba05d1c6879f79a05afb87caff24;p=p5sagit%2Fp5-mst-13.2.git Re: [PATCH scope.c] Re: local($tied->{foo}) leaks Message-ID: <20020503235110.E22026@fdgroup.com> p4raw-id: //depot/perl@16386 --- diff --git a/pp_hot.c b/pp_hot.c index 027d124..30653a7 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1682,8 +1682,17 @@ PP(pp_helem) STRLEN keylen; char *key = SvPV(keysv, keylen); SAVEDELETE(hv, savepvn(key,keylen), keylen); - } else + } else { + SV *sv; 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) @@ -2938,8 +2947,17 @@ PP(pp_aelem) PUSHs(lv); RETURN; } - if (PL_op->op_private & OPpLVAL_INTRO) + if (PL_op->op_private & OPpLVAL_INTRO) { + SV *sv; 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); } diff --git a/scope.c b/scope.c index a7d55b0..85a0680 100644 --- a/scope.c +++ b/scope.c @@ -206,12 +206,6 @@ S_save_scalar_at(pTHX_ SV **sptr) PL_localizing = 1; SvSETMAGIC(sv); PL_localizing = 0; - /* If we're localizing a tied array/hash element, this new sv - * won't actually be stored in the array/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); } return sv; }