Tests: Prevent array reallocations during ts_stack_print_dot_graph

When debugging a test with 'script/test -D', the DOT-graph generation
code was sometimes causing reallocations that were not captured by the
allocation tracker, because we explicitly disable allocation-tracking
for that method in order to reduce noise when debugging memory leaks.

By growing the relevant array *prior* to turning off allocation
tracking, we can ensure that it is not reallocated within that function,
avoiding false positive memory leak errors.

Fixes #302
This commit is contained in:
Max Brunsfeld 2019-03-14 13:59:09 -07:00
parent 1e585d506f
commit 006a931ab8
3 changed files with 7 additions and 9 deletions

View file

@ -712,9 +712,9 @@ void ts_stack_clear(Stack *self) {
}
bool ts_stack_print_dot_graph(Stack *self, const TSLanguage *language, FILE *f) {
array_reserve(&self->iterators, 32);
bool was_recording_allocations = ts_toggle_allocation_recording(false);
if (!f)
f = stderr;
if (!f) f = stderr;
fprintf(f, "digraph stack {\n");
fprintf(f, "rankdir=\"RL\";\n");