aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c1
-rw-r--r--pc.y2
-rw-r--r--tree.c11
-rw-r--r--tree.h2
4 files changed, 16 insertions, 0 deletions
diff --git a/main.c b/main.c
index 43eef9e..246bfb0 100644
--- a/main.c
+++ b/main.c
@@ -260,6 +260,7 @@ int main()
assert(cur_scope);
yyparse();
+ free_scope(cur_scope);
return 0;
}
diff --git a/pc.y b/pc.y
index 790610b..4a2d664 100644
--- a/pc.y
+++ b/pc.y
@@ -97,6 +97,7 @@ program
{
set_ret_type($9);
print_tree($9);
+ free_tree($4);
#ifdef DEBUG
print_scope(cur_scope);
#endif
@@ -168,6 +169,7 @@ sub_prog_declaration
{
set_ret_type($4);
print_tree($4);
+ free_tree($4);
#ifdef DEBUG
print_scope(cur_scope);
#endif
diff --git a/tree.c b/tree.c
index 35fe071..9b32f15 100644
--- a/tree.c
+++ b/tree.c
@@ -229,3 +229,14 @@ int spaces;
}
}
+
+void free_tree(t)
+ptree *t;
+{
+ if (!t)
+ return;
+
+ free_tree(t->l);
+ free_tree(t->r);
+ free(t);
+}
diff --git a/tree.h b/tree.h
index 0c0cd74..b0a1085 100644
--- a/tree.h
+++ b/tree.h
@@ -30,4 +30,6 @@ ptree* mkop(int, int, ptree*, ptree*);
void update_type_info(ptree*, ptree*);
void set_ret_type(ptree*);
+void free_tree(ptree*);
+
#endif