From: Chip Salzenberg Date: Tue, 28 Jan 1997 11:11:16 +0000 (+1200) Subject: Deref old stash when re-blessing X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2e3febc6b56a2d689b1b3f47d5fcfc7adade7965;p=p5sagit%2Fp5-mst-13.2.git Deref old stash when re-blessing --- diff --git a/sv.c b/sv.c index 0df2eec..5adbe8a 100644 --- a/sv.c +++ b/sv.c @@ -3865,19 +3865,23 @@ HV* stash; if (SvFLAGS(ref) & (SVs_OBJECT|SVf_READONLY)) { if (SvREADONLY(ref)) croak(no_modify); - if (SvOBJECT(ref) && SvTYPE(ref) != SVt_PVIO) - --sv_objcount; + if (SvOBJECT(ref)) { + if (SvTYPE(ref) != SVt_PVIO) + --sv_objcount; + SvREFCNT_dec(SvSTASH(ref)); + } } SvOBJECT_on(ref); - ++sv_objcount; + if (SvTYPE(ref) != SVt_PVIO) + ++sv_objcount; (void)SvUPGRADE(ref, SVt_PVMG); SvSTASH(ref) = (HV*)SvREFCNT_inc(stash); #ifdef OVERLOAD - SvAMAGIC_off(sv); - if (Gv_AMG(stash)) { - SvAMAGIC_on(sv); - } + if (Gv_AMG(stash)) + SvAMAGIC_on(sv); + else + SvAMAGIC_off(sv); #endif /* OVERLOAD */ return sv;