From 423b6db8558948f0c7886ccb68badf3bfb5bc8f4 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 19 Oct 2019 15:12:45 -0500 Subject: [PATCH] Fix memory leak with some string/ functions. kmp_init leaked memory when called with an empty string. --- src/core/string.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/string.c b/src/core/string.c index 44f943e2..b3bf78c6 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -104,13 +104,13 @@ static void kmp_init( struct kmp_state *s, const uint8_t *text, int32_t textlen, const uint8_t *pat, int32_t patlen) { + if (patlen == 0) { + janet_panic("expected non-empty pattern"); + } int32_t *lookup = calloc(patlen, sizeof(int32_t)); if (!lookup) { JANET_OUT_OF_MEMORY; } - if (patlen == 0) { - janet_panic("expected non-empty pattern"); - } s->lookup = lookup; s->i = 0; s->j = 0;