summaryrefslogtreecommitdiff
path: root/src/ast.c
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2023-01-08 15:39:19 -0800
committerPreston Pan <preston@nullring.xyz>2023-01-08 15:39:19 -0800
commit19367a27472a06634424e56c1eb21e4f53da4e9e (patch)
treefc58a08d36d451bdd1e7143a7358ac8a374355f7 /src/ast.c
parent87d82ead963c24d84a4f6e417b96b9bf73d132bb (diff)
fixed invalid read; some memory leakage fixed but not completely
Diffstat (limited to 'src/ast.c')
-rw-r--r--src/ast.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/ast.c b/src/ast.c
index eefbc45..ef2246e 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -94,3 +94,20 @@ bool is_proper_list(ast_t *e) {
return true;
return false;
}
+
+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) {
+ for (int i = 0; i < e->root_size; i++) {
+ ast_free(e->subnodes[i]);
+ }
+ }
+
+ free(e);
+}