From 29c77c34efdc55cf38bc85ef60ff38b687990129 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 2 Feb 2016 13:13:32 -0800 Subject: [PATCH] Avoid leaking copy of potentially-extra token --- src/runtime/parser.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/runtime/parser.c b/src/runtime/parser.c index d002e47f..8a008208 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -292,13 +292,17 @@ static ParseActionResult ts_parser__shift_extra(TSParser *self, int head, TSTree *lookahead) { TSSymbolMetadata metadata = self->language->symbol_metadata[lookahead->symbol]; if (metadata.structural && ts_stack_head_count(self->stack) > 1) { - lookahead = ts_tree_make_copy(lookahead); - if (!lookahead) + TSTree *copy = ts_tree_make_copy(lookahead); + if (!copy) return FailedToUpdateStackHead; + copy->extra = true; + ParseActionResult result = ts_parser__shift(self, head, state, copy); + ts_tree_release(copy); + return result; + } else { + lookahead->extra = true; + return ts_parser__shift(self, head, state, lookahead); } - - lookahead->extra = true; - return ts_parser__shift(self, head, state, lookahead); } static ParseActionResult ts_parser__reduce(TSParser *self, int head,