This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Install perlfaq and perlglossary manpages in section 1 of the manual
[perl5.git] / scope.c
diff --git a/scope.c b/scope.c
index 9ed6475..cb0e8c5 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -181,7 +181,7 @@ S_save_scalar_at(pTHX_ SV **sptr, const U32 flags)
     osv = *sptr;
     sv  = (flags & SAVEf_KEEPOLDELEM) ? osv : (*sptr = newSV(0));
 
-    if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) {
+    if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv)) {
        if (SvGMAGICAL(osv)) {
            SvFLAGS(osv) |= (SvFLAGS(osv) &
               (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
@@ -901,7 +901,10 @@ Perl_leave_scope(pTHX_ I32 base)
 
                if (SvTHINKFIRST(sv))
                    sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF);
+               if (SvTYPE(sv) == SVt_PVHV)
+                   Perl_hv_kill_backrefs(aTHX_ MUTABLE_HV(sv));
                if (SvMAGICAL(sv))
+                   sv_unmagic(sv, PERL_MAGIC_backref),
                    mg_free(sv);
 
                switch (SvTYPE(sv)) {
@@ -922,7 +925,8 @@ Perl_leave_scope(pTHX_ I32 base)
                SvPADSTALE_on(sv); /* mark as no longer live */
            }
            else {      /* Someone has a claim on this, so abandon it. */
-               const U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP);
+               assert(  SvFLAGS(sv) & SVs_PADMY);
+               assert(!(SvFLAGS(sv) & SVs_PADTMP));
                switch (SvTYPE(sv)) {   /* Console ourselves with a new value */
                case SVt_PVAV:  *(SV**)ptr = MUTABLE_SV(newAV());       break;
                case SVt_PVHV:  *(SV**)ptr = MUTABLE_SV(newHV());       break;
@@ -931,7 +935,7 @@ Perl_leave_scope(pTHX_ I32 base)
                SvREFCNT_dec(sv);       /* Cast current value to the winds. */
                /* preserve pad nature, but also mark as not live
                 * for any closure capturing */
-               SvFLAGS(*(SV**)ptr) |= padflags | SVs_PADSTALE;
+               SvFLAGS(*(SV**)ptr) |= (SVs_PADMY|SVs_PADSTALE);
            }
            break;
        case SAVEt_DELETE: