From: Jan Dubois Date: Thu, 17 Aug 2000 18:31:55 +0000 (-0700) Subject: newSVrv() memory leak X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0199fce9e831d70af0aeef6c5962dc695c3c246f;p=p5sagit%2Fp5-mst-13.2.git newSVrv() memory leak Message-ID: p4raw-id: //depot/perl@6687 --- diff --git a/sv.c b/sv.c index 9e77330..f065084 100644 --- a/sv.c +++ b/sv.c @@ -5534,8 +5534,23 @@ Perl_newSVrv(pTHX_ SV *rv, const char *classname) SV_CHECK_THINKFIRST(rv); SvAMAGIC_off(rv); + if (SvTYPE(rv) >= SVt_PVMG) { + U32 refcnt = SvREFCNT(rv); + SvREFCNT(rv) = 0; + sv_clear(rv); + SvFLAGS(rv) = 0; + SvREFCNT(rv) = refcnt; + } + if (SvTYPE(rv) < SVt_RV) - sv_upgrade(rv, SVt_RV); + sv_upgrade(rv, SVt_RV); + else if (SvTYPE(rv) > SVt_RV) { + (void)SvOOK_off(rv); + if (SvPVX(rv) && SvLEN(rv)) + Safefree(SvPVX(rv)); + SvCUR_set(rv, 0); + SvLEN_set(rv, 0); + } (void)SvOK_off(rv); SvRV(rv) = sv;