1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-16 05:34:48 +00:00

Fix memory leak with some string/ functions.

kmp_init leaked memory when called with an empty string.
This commit is contained in:
Calvin Rose 2019-10-19 15:12:45 -05:00
parent bb54b940c0
commit 423b6db855

View File

@ -104,13 +104,13 @@ static void kmp_init(
struct kmp_state *s, struct kmp_state *s,
const uint8_t *text, int32_t textlen, const uint8_t *text, int32_t textlen,
const uint8_t *pat, int32_t patlen) { const uint8_t *pat, int32_t patlen) {
if (patlen == 0) {
janet_panic("expected non-empty pattern");
}
int32_t *lookup = calloc(patlen, sizeof(int32_t)); int32_t *lookup = calloc(patlen, sizeof(int32_t));
if (!lookup) { if (!lookup) {
JANET_OUT_OF_MEMORY; JANET_OUT_OF_MEMORY;
} }
if (patlen == 0) {
janet_panic("expected non-empty pattern");
}
s->lookup = lookup; s->lookup = lookup;
s->i = 0; s->i = 0;
s->j = 0; s->j = 0;