# HG changeset patch # User Matti Hamalainen # Date 1587940313 -10800 # Node ID 838189b856f3fff60217a4002ec754bd68b98768 # Parent c91902120e795f15b030d9873a2694e5bc440aa2 Fix various memory leaks in th_regex. Not that it is usable anyway yet. diff -r c91902120e79 -r 838189b856f3 th_regex.c --- a/th_regex.c Mon Apr 27 01:28:14 2020 +0300 +++ b/th_regex.c Mon Apr 27 01:31:53 2020 +0300 @@ -708,7 +708,17 @@ out: *pexpr = ctx.data; - // Free temporary buffers + // Free parse context + for (size_t n = 0; n < ctx.nstack; n++) + { + if (ctx.stack[n] != ctx.data) + { + th_regex_free(ctx.stack[n]); + th_free(ctx.stack[n]); + } + } + th_free(ctx.stack); + th_free(tmp); th_free(ctx.buf); return res; @@ -736,6 +746,7 @@ } th_free(expr->nodes); + th_free(expr); } } @@ -1186,6 +1197,6 @@ */ void th_regex_free_matches(th_regex_match_t *matches) { - th_llist_free_func_node((th_llist_t *) matches, - (void (*)(th_llist_t *)) th_regex_free_match); + th_llist_free_func_data((th_llist_t *) matches, + (void (*)(void *)) th_regex_free_match); }