From 716ef245780a0ca671bdd91a9d7c1032f5dae042 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 18 Jan 2022 17:01:07 -0600 Subject: [PATCH] remove unfinished queries from 'ts_query_cursor_remove_match' --- lib/src/query.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/src/query.c b/lib/src/query.c index 470bcfd2..23fddceb 100644 --- a/lib/src/query.c +++ b/lib/src/query.c @@ -3725,6 +3725,20 @@ void ts_query_cursor_remove_match( return; } } + + // Remove unfinished query states as well to prevent future + // captures for a match being removed. + for (unsigned i = 0; i < self->states.size; i++) { + const QueryState *state = &self->states.contents[i]; + if (state->id == match_id) { + capture_list_pool_release( + &self->capture_list_pool, + state->capture_list_id + ); + array_erase(&self->states, i); + return; + } + } } bool ts_query_cursor_next_capture(