Skip to content

Commit 81c18b7

Browse files
committed
force_word, intuit_more: fix uni_normalize leaks
detected by coverity
1 parent 10b0b0d commit 81c18b7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

toke.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,14 +2235,16 @@ S_force_word(pTHX_ char *start, int token, int check_keyword, int allow_pack)
22352235
PL_expect = XOPERATOR;
22362236
}
22372237
}
2238-
start = PL_tokenbuf;
22392238
if (UNLIKELY(normalize)) {
2240-
start = pv_uni_normalize(start, len, &len);
2241-
Copy(start, PL_tokenbuf, len+1, char);
2239+
start = pv_uni_normalize(PL_tokenbuf, len, &len);
2240+
if (start != PL_tokenbuf) {
2241+
Copy(start, PL_tokenbuf, len+1, char);
2242+
Safefree(start);
2243+
}
22422244
}
22432245
NEXTVAL_NEXTTOKE.opval
22442246
= newSVOP(OP_CONST,0,
2245-
S_newSV_maybe_utf8(aTHX_ start, len));
2247+
S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
22462248
NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
22472249
force_next(token);
22482250
}
@@ -4335,7 +4337,10 @@ S_intuit_more(pTHX_ char *s)
43354337
if (len > 1) {
43364338
if (UNLIKELY(normalize)) {
43374339
tmp = pv_uni_normalize(tmpbuf, len, &len);
4338-
Copy(tmp, tmpbuf, len+1, char);
4340+
if (tmp != tmpbuf) {
4341+
Copy(tmp, tmpbuf, len+1, char);
4342+
Safefree(tmp);
4343+
}
43394344
}
43404345
if (gv_fetchpvn_flags(tmpbuf, len,
43414346
UTF ? SVf_UTF8 : 0, SVt_PV))

0 commit comments

Comments
 (0)