Fix memory leak in tree
This commit is contained in:
parent
7251456cd2
commit
8deeff392b
4 changed files with 12 additions and 7 deletions
|
|
@ -6,7 +6,7 @@ int main(int argc, char *argv[])
|
|||
"",
|
||||
"--no-color",
|
||||
"--only="
|
||||
// "reports errors inside of nested objects",
|
||||
""
|
||||
};
|
||||
return bandit::run(4, const_cast<char **>(args));
|
||||
}
|
||||
|
|
@ -1,5 +1,12 @@
|
|||
#include "spec_helper.h"
|
||||
|
||||
static ts_tree ** tree_array(vector<ts_tree *> trees) {
|
||||
ts_tree ** result = (ts_tree **)calloc(trees.size(), sizeof(ts_tree *));
|
||||
for (int i = 0; i < trees.size(); i++)
|
||||
result[i] = trees[i];
|
||||
return result;
|
||||
}
|
||||
|
||||
START_TEST
|
||||
|
||||
enum { cat, dog, pig };
|
||||
|
|
@ -23,7 +30,7 @@ describe("trees", []() {
|
|||
ts_tree *tree2 = ts_tree_make_leaf(cat);
|
||||
AssertThat(ts_tree_equals(tree1, tree2), Equals(1));
|
||||
|
||||
ts_tree *parent2 = ts_tree_make_node(dog, 1, &tree2);
|
||||
ts_tree *parent2 = ts_tree_make_node(dog, 1, tree_array({ tree2 }));
|
||||
AssertThat(ts_tree_equals(parent1, parent2), Equals(1));
|
||||
|
||||
ts_tree_release(tree2);
|
||||
|
|
@ -34,10 +41,10 @@ describe("trees", []() {
|
|||
ts_tree *different_tree = ts_tree_make_leaf(pig);
|
||||
AssertThat(ts_tree_equals(tree1, different_tree), Equals(0));
|
||||
|
||||
ts_tree *different_parent = ts_tree_make_node(dog, 1, &different_tree);
|
||||
ts_tree *different_parent = ts_tree_make_node(dog, 1, tree_array({ different_tree }));
|
||||
AssertThat(ts_tree_equals(parent1, different_parent), Equals(0));
|
||||
|
||||
ts_tree *parent_with_same_type = ts_tree_make_node(cat, 1, &different_parent);
|
||||
ts_tree *parent_with_same_type = ts_tree_make_node(cat, 1, tree_array({ different_parent }));
|
||||
AssertThat(ts_tree_equals(parent_with_same_type, tree1), Equals(0));
|
||||
AssertThat(ts_tree_equals(tree1, parent_with_same_type), Equals(0));
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@
|
|||
#include "rules/built_in_symbols.h"
|
||||
#include "first_set.h"
|
||||
|
||||
#include "stream_methods.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::pair;
|
||||
using std::string;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ void ts_tree_release(ts_tree *tree) {
|
|||
ts_tree **children = tree->data.children.contents;
|
||||
for (int i = 0; i < ts_tree_child_count(tree); i++)
|
||||
ts_tree_release(children[i]);
|
||||
// free(children);
|
||||
free(children);
|
||||
free(tree);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue