From 523923bd93e524223ed49096e16d16cef9f365cd Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 10 Mar 2016 21:26:21 -0800 Subject: [PATCH] Ensure reduce only produces one slice when stopping at errors --- src/runtime/stack.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/runtime/stack.c b/src/runtime/stack.c index 4701c29c..37774741 100644 --- a/src/runtime/stack.c +++ b/src/runtime/stack.c @@ -447,10 +447,17 @@ StackPopResult ts_stack_pop_count(Stack *self, int head_index, int count) { stack__pop(self, head_index, stack__pop_count_callback, &session); int status; if (slices.size) { - if (session.found_error) + if (session.found_error) { status = StackPopStoppedAtError; - else + array_reverse(&slices); + while (slices.size > 1) { + StackSlice slice = array_pop(&slices); + ts_tree_array_delete(&slice.trees); + ts_stack_remove_head(self, slice.head_index); + } + } else { status = StackPopSucceeded; + } } else { status = StackPopFailed; }