summaryrefslogtreecommitdiff
path: root/src/ast.c
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2023-01-08 19:17:57 -0800
committerPreston Pan <preston@nullring.xyz>2023-01-08 19:17:57 -0800
commit43f11a93385c4848bfad49510bdea2849f241816 (patch)
treeaafe396ad077acc6be6bef1d77a65d517cd30cf4 /src/ast.c
parent19367a27472a06634424e56c1eb21e4f53da4e9e (diff)
add some frees; still need to fix high amounts of memory leakage
Diffstat (limited to 'src/ast.c')
-rw-r--r--src/ast.c22
1 files changed, 12 insertions, 10 deletions
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);
}