summaryrefslogtreecommitdiff
path: root/comp/lucas-standen-NEA/code
diff options
context:
space:
mode:
authorstandenboy <standenboy@seacrossedlovers.xyz>2024-05-07 15:00:06 +0100
committerstandenboy <standenboy@seacrossedlovers.xyz>2024-05-07 15:00:06 +0100
commit907e5ad4c33efe2c9e35ba60b3fe7979e1120166 (patch)
tree4b370f5bded11f24ef382062c3dc57a3a85616cb /comp/lucas-standen-NEA/code
parentf6545306458de107e5ad08a3a2dc54e6d1bbc780 (diff)
fixed mem leak in proto
Diffstat (limited to 'comp/lucas-standen-NEA/code')
-rw-r--r--comp/lucas-standen-NEA/code/proto/ast/Makefile4
-rwxr-xr-xcomp/lucas-standen-NEA/code/proto/ast/astbin20792 -> 24200 bytes
-rw-r--r--comp/lucas-standen-NEA/code/proto/ast/astg.c25
3 files changed, 18 insertions, 11 deletions
diff --git a/comp/lucas-standen-NEA/code/proto/ast/Makefile b/comp/lucas-standen-NEA/code/proto/ast/Makefile
index e11e20f..6074b00 100644
--- a/comp/lucas-standen-NEA/code/proto/ast/Makefile
+++ b/comp/lucas-standen-NEA/code/proto/ast/Makefile
@@ -1,4 +1,4 @@
all: astg ast.c
- cc ast.c astg.o -o ast
+ cc -ggdb ast.c astg.o -o ast
astg: astg.c
- cc astg.c -c -o astg.o
+ cc -ggdb astg.c -c -o astg.o
diff --git a/comp/lucas-standen-NEA/code/proto/ast/ast b/comp/lucas-standen-NEA/code/proto/ast/ast
index b4b4f9f..817c30e 100755
--- a/comp/lucas-standen-NEA/code/proto/ast/ast
+++ b/comp/lucas-standen-NEA/code/proto/ast/ast
Binary files differ
diff --git a/comp/lucas-standen-NEA/code/proto/ast/astg.c b/comp/lucas-standen-NEA/code/proto/ast/astg.c
index fc6fc8f..e96b771 100644
--- a/comp/lucas-standen-NEA/code/proto/ast/astg.c
+++ b/comp/lucas-standen-NEA/code/proto/ast/astg.c
@@ -19,11 +19,25 @@ typedef struct ast_node {
ast_node *left;
} ast_node;
+void freeAst(ast_node *head){
+ if (head->left != NULL)
+ freeAst(head->left);
+ if (head->right != NULL)
+ freeAst(head->left);
+ free(head);
+}
+
int exec(ast_node *exp){
- if (exp->left != NULL)
+ if (exp->left != NULL){
exp->realLeft = exec(exp->left);
- if (exp->right != NULL)
+ freeAst(exp->left);
+ exp->left = NULL;
+ }
+ if (exp->right != NULL){
exp->realRight = exec(exp->right);
+ freeAst(exp->right);
+ exp->right = NULL;
+ }
if (exp->operation == ADD)
return exp->realLeft+ exp->realRight;
@@ -36,10 +50,3 @@ int exec(ast_node *exp){
return 0;
}
-void freeAst(ast_node *head){
- if (head->left != NULL)
- freeAst(head->left);
- if (head->right != NULL)
- freeAst(head->left);
- free(head);
-}