From: Rafael Garcia-Suarez Date: Fri, 29 Jun 2007 16:28:34 +0000 (+0000) Subject: Removes the code that is supposed to restore magic on leaving the X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c4a7531db1b7667c9d43fd3494f5bbf4901ff149;p=p5sagit%2Fp5-mst-13.2.git Removes the code that is supposed to restore magic on leaving the localization of an array or a hash. This fixes some memory leaks. Basically we were overwriting the magic of the outer value (value from the outer scope) by the magic of the inner value (therefore making that outer magic leaking in memory). But that inner magic was created by mg_localize() by copying *some* of the outer magic. Consequently the outer value already has that magic. So just keep it and don't bother. That change might introduce obscure bugs. On the other hand, it might also cure obscure bugs, related to the inner value acquiring container magic during its lifetime, or to the outer value loosing non-container magic. No test in the test suite seems to test that. p4raw-id: //depot/perl@31505 --- diff --git a/scope.c b/scope.c index c9700b3..17b7789 100644 --- a/scope.c +++ b/scope.c @@ -680,15 +680,7 @@ Perl_leave_scope(pTHX_ I32 base) av = (AV*)SSPOPPTR; gv = (GV*)SSPOPPTR; if (GvAV(gv)) { - AV * const goner = GvAV(gv); - /* FIXME - this is a temporary hack until we work out what - the correct behaviour for magic should be. */ - sv_unmagic((SV*)goner, PERL_MAGIC_arylen_p); - SvMAGIC_set(av, SvMAGIC(goner)); - SvFLAGS((SV*)av) |= SvMAGICAL(goner); - SvMAGICAL_off(goner); - SvMAGIC_set(goner, NULL); - SvREFCNT_dec(goner); + SvREFCNT_dec(GvAV(gv)); } GvAV(gv) = av; if (SvMAGICAL(av)) { @@ -701,12 +693,7 @@ Perl_leave_scope(pTHX_ I32 base) hv = (HV*)SSPOPPTR; gv = (GV*)SSPOPPTR; if (GvHV(gv)) { - HV * const goner = GvHV(gv); - SvMAGIC_set(hv, SvMAGIC(goner)); - SvFLAGS(hv) |= SvMAGICAL(goner); - SvMAGICAL_off(goner); - SvMAGIC_set(goner, NULL); - SvREFCNT_dec(goner); + SvREFCNT_dec(GvHV(gv)); } GvHV(gv) = hv; if (SvMAGICAL(hv)) {