With Damian's approval synchronize damian's modules'
[p5sagit/p5-mst-13.2.git] / scope.c
diff --git a/scope.c b/scope.c
index d4ea391..106b3dc 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -196,7 +196,7 @@ S_save_scalar_at(pTHX_ SV **sptr)
        if (SvGMAGICAL(osv)) {
            MAGIC* mg;
            bool oldtainted = PL_tainted;
-           mg_get(osv);
+           mg_get(osv);                /* note, can croak! */
            if (PL_tainting && PL_tainted && (mg = mg_find(osv, 't'))) {
                SAVESPTR(mg->mg_obj);
                mg->mg_obj = osv;
@@ -678,13 +678,19 @@ Perl_leave_scope(pTHX_ I32 base)
                SvMAGICAL_off(sv);
                SvMAGIC(sv) = 0;
            }
+           /* XXX this branch is pretty bogus--note that we seem to
+            * only get here if the mg_get() in save_scalar_at() ends
+            * up croaking.  This code irretrievably clears(!) the magic
+            * on the SV to avoid further croaking that might ensue
+            * when the SvSETMAGIC() below is called.  This needs a
+            * total rethink.  --GSAR */
            else if (SvTYPE(value) >= SVt_PVMG && SvMAGIC(value) &&
                     SvTYPE(value) != SVt_PVGV)
            {
                SvFLAGS(value) |= (SvFLAGS(value) &
                                   (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
                SvMAGICAL_off(value);
-               SvMAGIC(value) = 0;
+               mg_free(value);
            }
             SvREFCNT_dec(sv);
            *(SV**)ptr = value;
@@ -852,7 +858,7 @@ Perl_leave_scope(pTHX_ I32 base)
            ptr = SSPOPPTR;
            (void)hv_delete(hv, (char*)ptr, (U32)SSPOPINT, G_DISCARD);
            SvREFCNT_dec(hv);
-           /* Safefree(ptr); */ /* Does not work with shared strings. */
+           Safefree(ptr); 
            break;
        case SAVEt_DESTRUCTOR:
            ptr = SSPOPPTR;
@@ -912,10 +918,6 @@ Perl_leave_scope(pTHX_ I32 base)
            PL_op = (OP*)SSPOPPTR;
            break;
        case SAVEt_HINTS:
-           if (GvHV(PL_hintgv)) {
-               SvREFCNT_dec((SV*)GvHV(PL_hintgv));
-               GvHV(PL_hintgv) = NULL;
-           }
            *(I32*)&PL_hints = (I32)SSPOPINT;
            break;
        case SAVEt_COMPPAD: