From 261a935dfa322ddcf8e9396099e6a4d8fca49ab5 Mon Sep 17 00:00:00 2001 From: SIGMazer Date: Sat, 8 Feb 2025 10:08:01 +0200 Subject: [PATCH] ci(memoryl_leaks): Fix CI valgrind check and resolve function memory leaks Signed-off-by: SIGMazer --- ast.c | 3 +++ run_valgrind_tests.sh | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ast.c b/ast.c index dcd6917..251b28a 100644 --- a/ast.c +++ b/ast.c @@ -3435,6 +3435,7 @@ void free_ast(ASTNode *node) case NODE_FUNCTION_DEF: SAFE_FREE(node->data.function_def.name); // Free parameters + free_parameters(node->data.function_def.parameters); if (node->data.function_def.body) { free_ast(node->data.function_def.body); @@ -3786,6 +3787,7 @@ void enter_function_scope(Function *func, ArgumentList *args) Variable *var = variable_new(curr_param->name); var->var_type = curr_param->type; add_variable_to_scope(curr_param->name, var); + SAFE_FREE(var); switch (curr_param->type) { @@ -3810,5 +3812,6 @@ void enter_function_scope(Function *func, ArgumentList *args) } curr_param = curr_param->next; } + reverse_parameter_list(&func->parameters); } diff --git a/run_valgrind_tests.sh b/run_valgrind_tests.sh index 9a08640..52e8a90 100755 --- a/run_valgrind_tests.sh +++ b/run_valgrind_tests.sh @@ -18,5 +18,9 @@ for f in test_cases/*.brainrot; do else valgrind --leak-check=full --error-exitcode=1 ./brainrot "$f" fi + if [[ $? -ne 0 ]]; then + echo "Valgrind failed on $f" + exit 1 + fi echo -done \ No newline at end of file +done