From 42fe4f6b333e9a0dddb0d9cd263efc25ab0e80f1 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Fri, 12 Aug 2022 14:42:49 +0200 Subject: [PATCH] matcher: Fix relying on GC'ed milist in deinit function When the GC calls the matchers deinit function, the milist (also an GC-able object) might already have been deinitialized, so we can't use the count values from there. Maybe milist should actually be refcounted? It doesn't build cycles and doesn't reference other GC objects. This would simplify it and remove the now duplicated count data. --- src/matcher.c | 8 ++++++-- src/matcher.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/matcher.c b/src/matcher.c index 4e7ed3b..bfa7a87 100644 --- a/src/matcher.c +++ b/src/matcher.c @@ -24,6 +24,8 @@ apfl_matcher_new(struct gc *gc, struct matcher_instruction_list *milist) { struct matcher matcher = { .instructions = milist, + .value_count = 0, + .capture_count = 0, .values = NULL, .captures = NULL, .result = false, @@ -32,10 +34,12 @@ apfl_matcher_new(struct gc *gc, struct matcher_instruction_list *milist) if (!init_values_list(gc->allocator, &matcher.values, milist->value_count)) { goto error; } + matcher.value_count = milist->value_count; if (!init_values_list(gc->allocator, &matcher.captures, milist->capture_count)) { goto error; } + matcher.capture_count = milist->capture_count; struct matcher *gc_matcher = apfl_gc_new_matcher(gc); if (gc_matcher == NULL) { @@ -54,8 +58,8 @@ error: void apfl_matcher_deinit(struct apfl_allocator allocator, struct matcher *matcher) { - FREE_LIST(allocator, matcher->values, matcher->instructions->value_count); - FREE_LIST(allocator, matcher->captures, matcher->instructions->capture_count); + FREE_LIST(allocator, matcher->values, matcher->value_count); + FREE_LIST(allocator, matcher->captures, matcher->capture_count); } void diff --git a/src/matcher.h b/src/matcher.h index fbe5cfa..36dbb93 100644 --- a/src/matcher.h +++ b/src/matcher.h @@ -11,6 +11,8 @@ extern "C" { struct matcher { struct matcher_instruction_list *instructions; + size_t value_count; + size_t capture_count; struct apfl_value *values; struct apfl_value *captures; bool result;