Skip to content

Commit

Permalink
Fixed memory leak when editing trees.
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmurray committed Oct 29, 2023
1 parent 16eccca commit 1d513c8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ std::string Parser::preprocess(const std::string& file) {
/* update tree */
TSInputEdit edit{k, old_size, new_size, from, root_to, root_to};
ts_tree_edit(tree, &edit);
tree = ts_parser_parse_string(parser, tree, in.data(), in.size());
ts_parser_reset(parser);
TSTree* old_tree = tree;
tree = ts_parser_parse_string(parser, old_tree, in.data(), in.size());
ts_tree_delete(old_tree);
root = ts_tree_root_node(tree);

/* restore cursor to same position as edit */
Expand Down Expand Up @@ -249,7 +252,10 @@ std::string Parser::preprocess(const std::string& file) {
/* update tree */
TSInputEdit edit{k, old_size, new_size, from, root_to, root_to};
ts_tree_edit(tree, &edit);
tree = ts_parser_parse_string(parser, tree, in.data(), in.size());
ts_parser_reset(parser);
TSTree* old_tree = tree;
tree = ts_parser_parse_string(parser, old_tree, in.data(), in.size());
ts_tree_delete(old_tree);
root = ts_tree_root_node(tree);

/* restore cursor to same byte position as edit */
Expand Down

0 comments on commit 1d513c8

Please sign in to comment.