Fix last few leaks, add leak checking to all randomized specs
This commit is contained in:
parent
f6f02182c1
commit
2f2ca401be
3 changed files with 36 additions and 24 deletions
|
|
@ -1,16 +1,18 @@
|
|||
#include "spec_helper.h"
|
||||
#include "runtime/alloc.h"
|
||||
#include "helpers/test_languages.h"
|
||||
#include "helpers/read_test_entries.h"
|
||||
#include "helpers/spy_input.h"
|
||||
#include "helpers/log_debugger.h"
|
||||
#include "helpers/point_helpers.h"
|
||||
#include "helpers/encoding_helpers.h"
|
||||
#include "helpers/record_alloc.h"
|
||||
#include <set>
|
||||
|
||||
static void expect_the_correct_tree(TSNode node, TSDocument *document, string tree_string) {
|
||||
const char *node_string = ts_node_string(node, document);
|
||||
AssertThat(node_string, Equals(tree_string));
|
||||
free((void *)node_string);
|
||||
ts_free((void *)node_string);
|
||||
}
|
||||
|
||||
static void expect_a_consistent_tree(TSNode node, TSDocument *document) {
|
||||
|
|
@ -105,6 +107,7 @@ describe("The Corpus", []() {
|
|||
TSDocument *document;
|
||||
|
||||
before_each([&]() {
|
||||
record_alloc::start();
|
||||
document = ts_document_make();
|
||||
ts_document_set_language(document, get_test_language(language_name));
|
||||
// ts_document_set_debugger(document, log_debugger_make(true));
|
||||
|
|
@ -112,6 +115,7 @@ describe("The Corpus", []() {
|
|||
|
||||
after_each([&]() {
|
||||
ts_document_free(document);
|
||||
AssertThat(record_alloc::outstanding_allocation_indices(), IsEmpty());
|
||||
});
|
||||
|
||||
for (auto &entry : read_corpus_entries(language_dir + "/grammar_test")) {
|
||||
|
|
|
|||
|
|
@ -605,28 +605,35 @@ static ParseActionResult ts_parser__accept(TSParser *self, int head) {
|
|||
TSTree *root = pop_result->trees[i];
|
||||
size_t leading_extra_count = i;
|
||||
size_t trailing_extra_count = pop_result->tree_count - 1 - i;
|
||||
TSTree **new_children = ts_calloc(
|
||||
root->child_count + leading_extra_count + trailing_extra_count,
|
||||
sizeof(TSTree *));
|
||||
if (!new_children)
|
||||
goto error;
|
||||
|
||||
if (leading_extra_count > 0)
|
||||
memcpy(new_children, pop_result->trees,
|
||||
leading_extra_count * sizeof(TSTree *));
|
||||
if (root->child_count > 0)
|
||||
memcpy(new_children + leading_extra_count, root->children,
|
||||
root->child_count * sizeof(TSTree *));
|
||||
if (trailing_extra_count > 0)
|
||||
memcpy(new_children + leading_extra_count + root->child_count,
|
||||
pop_result->trees + leading_extra_count + 1,
|
||||
trailing_extra_count * sizeof(TSTree *));
|
||||
size_t new_count =
|
||||
root->child_count + leading_extra_count + trailing_extra_count;
|
||||
ts_tree_set_children(root, new_count, new_children);
|
||||
|
||||
if (new_count > 0) {
|
||||
TSTree **new_children = ts_calloc(new_count, sizeof(TSTree *));
|
||||
if (!new_children)
|
||||
goto error;
|
||||
if (leading_extra_count > 0)
|
||||
memcpy(new_children, pop_result->trees,
|
||||
leading_extra_count * sizeof(TSTree *));
|
||||
if (root->child_count > 0)
|
||||
memcpy(new_children + leading_extra_count, root->children,
|
||||
root->child_count * sizeof(TSTree *));
|
||||
if (trailing_extra_count > 0)
|
||||
memcpy(new_children + leading_extra_count + root->child_count,
|
||||
pop_result->trees + leading_extra_count + 1,
|
||||
trailing_extra_count * sizeof(TSTree *));
|
||||
ts_tree_set_children(root, new_count, new_children);
|
||||
}
|
||||
|
||||
ts_parser__remove_head(self, pop_result->head_index);
|
||||
self->finished_tree =
|
||||
ts_parser__select_tree(self, self->finished_tree, root);
|
||||
TSTree *tree = ts_parser__select_tree(self, self->finished_tree, root);
|
||||
if (tree == root) {
|
||||
ts_tree_release(self->finished_tree);
|
||||
self->finished_tree = root;
|
||||
} else {
|
||||
ts_tree_release(root);
|
||||
}
|
||||
|
||||
ts_free(pop_result->trees);
|
||||
break;
|
||||
}
|
||||
|
|
@ -834,10 +841,8 @@ TSTree *ts_parser_parse(TSParser *self, TSInput input, TSTree *previous_tree) {
|
|||
ts_stack_head_count(self->stack),
|
||||
ts_stack_top_state(self->stack, head), position.chars);
|
||||
|
||||
if (position.chars == last_position.chars &&
|
||||
ts_parser__can_reuse(self, head, lookahead)) {
|
||||
ts_tree_retain(lookahead);
|
||||
} else {
|
||||
if (position.chars != last_position.chars ||
|
||||
!ts_parser__can_reuse(self, head, lookahead)) {
|
||||
ts_tree_release(lookahead);
|
||||
lookahead = ts_parser__get_next_lookahead(self, head);
|
||||
if (!lookahead)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ static inline Vector vector_new(size_t element_size) {
|
|||
}
|
||||
|
||||
static inline bool vector_grow(Vector *self, size_t capacity) {
|
||||
if (capacity == 0)
|
||||
return true;
|
||||
|
||||
void *new_contents;
|
||||
if (self->contents)
|
||||
new_contents = ts_realloc(self->contents, capacity * self->element_size);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue