From: Nicholas Clark Date: Thu, 28 Apr 2005 09:29:06 +0000 (+0000) Subject: Calling sv_backoff() on something that's about to be free()d will X-Git-Tag: accepted/trunk/20130322.191538~20848 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5228ca4e093950c8cd059c706dfbce052f74fa4d;p=platform%2Fupstream%2Fperl.git Calling sv_backoff() on something that's about to be free()d will memmov() memory that's about to be freed. Seems wasteful. p4raw-id: //depot/perl@24344 --- diff --git a/sv.c b/sv.c index 0757341..5353df2 100644 --- a/sv.c +++ b/sv.c @@ -4416,9 +4416,16 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, register SV *sstr, I32 flags) return; } if (SvPVX(dstr)) { - (void)SvOOK_off(dstr); /* backoff */ - if (SvLEN(dstr)) - Safefree(SvPVX(dstr)); + if (SvLEN(dstr)) { + /* Unwrap the OOK offset by hand, to save a needless + memmove on memory that's about to be free()d. */ + char *pv = SvPVX(dstr); + if (SvOOK(dstr)) { + pv -= SvIVX(dstr); + SvFLAGS(dstr) &= ~SVf_OOK; + } + Safefree(pv); + } SvLEN_set(dstr, 0); SvCUR_set(dstr, 0); } @@ -5945,7 +5952,11 @@ Perl_sv_clear(pTHX_ register SV *sv) case SVt_PVNV: case SVt_PVIV: freescalar: - SvOOK_off(sv); + /* Don't bother with SvOOK_off(sv); as we're only going to free it. */ + if (SvOOK(sv)) { + SvPV_set(sv, SvPVX(sv) - SvIVX(sv)); + /* Don't even bother with turning off the OOK flag. */ + } /* FALL THROUGH */ case SVt_PV: case SVt_RV: