From: Jarkko Hietaniemi Date: Sun, 23 Jan 2005 21:25:01 +0000 (+0200) Subject: Re: Smoke [5.9.2] 23863 FAIL(F) MSWin32 WinXP/.Net SP1 (x86/1 cpu) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=128c951743744da884743c814b7b2e8304bf26d0;p=p5sagit%2Fp5-mst-13.2.git Re: Smoke [5.9.2] 23863 FAIL(F) MSWin32 WinXP/.Net SP1 (x86/1 cpu) Message-Id: <41F3FA0D.4010301@iki.fi> The uc() memory reduction patch had a memory leak... p4raw-id: //depot/perl@23869 --- diff --git a/pp.c b/pp.c index 09b0c7c..7185f03 100644 --- a/pp.c +++ b/pp.c @@ -3583,8 +3583,10 @@ PP(pp_uc) SETs(TARG); } else { + STRLEN min = len + 1; + (void)SvUPGRADE(TARG, SVt_PV); - SvGROW(TARG, len + 1); + SvGROW(TARG, min); (void)SvPOK_only(TARG); d = (U8*)SvPVX(TARG); send = s + len; @@ -3592,14 +3594,16 @@ PP(pp_uc) STRLEN u = UTF8SKIP(s); toUPPER_utf8(s, tmpbuf, &ulen); - if (ulen > u) { + if (ulen > u && (SvLEN(TARG) < (min += ulen - u))) { + /* If the eventually required minimum size outgrows + * the available space, we need to grow. */ UV o = d - (U8*)SvPVX(TARG); /* If someone uppercases one million U+03B0s we * SvGROW() one million times. Or we could try * guessing how much to allocate without allocating * too much. Such is life. */ - SvGROW(TARG, SvLEN(TARG) + ulen - u); + SvGROW(TARG, min); d = (U8*)SvPVX(TARG) + o; } Copy(tmpbuf, d, ulen, U8); @@ -3662,8 +3666,10 @@ PP(pp_lc) SETs(TARG); } else { + STRLEN min = len + 1; + (void)SvUPGRADE(TARG, SVt_PV); - SvGROW(TARG, len + 1); + SvGROW(TARG, min); (void)SvPOK_only(TARG); d = (U8*)SvPVX(TARG); send = s + len; @@ -3690,14 +3696,16 @@ PP(pp_lc) * See lib/unicore/SpecialCasing.txt. */ } - if (ulen > u) { + if (ulen > u && (SvLEN(TARG) < (min += ulen - u))) { + /* If the eventually required minimum size outgrows + * the available space, we need to grow. */ UV o = d - (U8*)SvPVX(TARG); /* If someone lowercases one million U+0130s we * SvGROW() one million times. Or we could try * guessing how much to allocate without allocating. * too much. Such is life. */ - SvGROW(TARG, SvLEN(TARG) + ulen - u); + SvGROW(TARG, min); d = (U8*)SvPVX(TARG) + o; } Copy(tmpbuf, d, ulen, U8);