diff options
author | Preston Pan <preston@nullring.xyz> | 2023-01-08 19:17:57 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2023-01-08 19:17:57 -0800 |
commit | 43f11a93385c4848bfad49510bdea2849f241816 (patch) | |
tree | aafe396ad077acc6be6bef1d77a65d517cd30cf4 /src/ast.c | |
parent | 19367a27472a06634424e56c1eb21e4f53da4e9e (diff) |
add some frees; still need to fix high amounts of memory leakage
Diffstat (limited to 'src/ast.c')
-rw-r--r-- | src/ast.c | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -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); } |