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:
parent
1e585d506f
commit
006a931ab8
3 changed files with 7 additions and 9 deletions
|
|
@ -98,7 +98,9 @@ extern "C" fn ts_record_free(ptr: *mut c_void) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn ts_record_allocations_toggle() {
|
||||
extern "C" fn ts_toggle_allocation_recording(enabled: bool) -> bool {
|
||||
let mut recorder = RECORDER.lock();
|
||||
recorder.enabled = !recorder.enabled;
|
||||
let was_enabled = recorder.enabled;
|
||||
recorder.enabled = enabled;
|
||||
was_enabled
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ void *ts_record_malloc(size_t);
|
|||
void *ts_record_calloc(size_t, size_t);
|
||||
void *ts_record_realloc(void *, size_t);
|
||||
void ts_record_free(void *);
|
||||
bool ts_record_allocations_toggle(bool);
|
||||
bool ts_toggle_allocation_recording(bool);
|
||||
|
||||
static inline void *ts_malloc(size_t size) {
|
||||
return ts_record_malloc(size);
|
||||
|
|
@ -33,10 +33,6 @@ static inline void ts_free(void *buffer) {
|
|||
ts_record_free(buffer);
|
||||
}
|
||||
|
||||
static inline bool ts_toggle_allocation_recording(bool value) {
|
||||
return ts_record_allocations_toggle(value);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue