From 43f11a93385c4848bfad49510bdea2849f241816 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Sun, 8 Jan 2023 19:17:57 -0800 Subject: add some frees; still need to fix high amounts of memory leakage --- src/ast.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/ast.c') diff --git a/src/ast.c b/src/ast.c index ef2246e..5325ebe 100644 --- a/src/ast.c +++ b/src/ast.c @@ -96,18 +96,20 @@ bool is_proper_list(ast_t *e) { } void ast_free(ast_t *e) { - if (e->cdr != NULL) { - ast_free(e->cdr); - } - if (e->car != NULL) { - ast_free(e->car); - } - - if (e->type == AST_ROOT) { + if (e->type == AST_PAIR) { + ast_t *cur = e; + ast_t *tmp; + while (cur != NULL) { + tmp = cur; + cur = cur->cdr; + free(tmp); + } + } else if (e->type == AST_ROOT) { for (int i = 0; i < e->root_size; i++) { ast_free(e->subnodes[i]); } + free(e); + } else { + free(e); } - - free(e); } -- cgit