Integrate changes #8704,8710 from pureperl.
Jarkko Hietaniemi [Fri, 9 Feb 2001 16:24:03 +0000 (16:24 +0000)]
Fixed UMRs and leak in Perl_pmtrans()

Several leaks an UMRs fixed, mainly in the area of Perl_pmtrans and
associated UTFied tr/// code.  Also fixed scoping leak of
PL_reg_start_tmp.

p4raw-link: @8710 on //depot/maint-5.6/pureperl: 4b295d51b64a7a209f5040a76fc8fbb310bcc094
p4raw-link: @8704 on //depot/maint-5.6/pureperl: a0f842d35079c52aadb60790fe59b37d9727c9a9

p4raw-id: //depot/perl@8735
p4raw-integrated: from //depot/maint-5.6/pureperl@8734 'edit in' op.c
(@8704..) 'merge in' regcomp.c (@8694..)

op.c

diff --git a/op.c b/op.c
index 95a72fc..379d7e9 100644 (file)
--- a/op.c
+++ b/op.c
@@ -2693,7 +2693,7 @@ Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
            while (t < tend) {
                cp[i++] = t;
                t += UTF8SKIP(t);
-               if (*t == 0xff) {
+               if (t < tend && *t == 0xff) {
                    t++;
                    t += UTF8SKIP(t);
                }
@@ -2701,7 +2701,7 @@ Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
            qsort(cp, i, sizeof(U8*), utf8compare);
            for (j = 0; j < i; j++) {
                U8 *s = cp[j];
-               I32 cur = j < i ? cp[j+1] - s : tend - s;
+               I32 cur = j < i - 1 ? cp[j+1] - s : tend - s;
                UV  val = utf8_to_uv(s, cur, &ulen, 0);
                s += ulen;
                diff = val - nextmin;
@@ -2714,7 +2714,7 @@ Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
                        sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
                    }
                }
-               if (*s == 0xff)
+               if (s < tend && *s == 0xff)
                    val = utf8_to_uv(s+1, cur - 1, &ulen, 0);
                if (val >= nextmin)
                    nextmin = val + 1;
@@ -2727,6 +2727,7 @@ Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
            t = (U8*)SvPVX(transv);
            tlen = SvCUR(transv);
            tend = t + tlen;
+           Safefree(cp);
        }
        else if (!rlen && !del) {
            r = t; rlen = tlen; rend = tend;
@@ -2819,6 +2820,7 @@ Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
        else
            bits = 8;
 
+       Safefree(cPVOPo->op_pv);
        cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none);
        SvREFCNT_dec(listsv);
        if (transv)