compile: fix memory leaks

This commit is contained in:
2026-05-30 19:52:24 +01:00
parent a30e76e525
commit 26b368a512
5 changed files with 56 additions and 6 deletions
+39
View File
@@ -0,0 +1,39 @@
#include <bshell/ast.h>
#include <bshell/compile.h>
#include <bshell/parse/token.h>
#include <bshell/status.h>
enum bshell_status bshell_compile_function(
struct bshell_ast_node *src,
bshell_function **out)
{
struct bshell_func_ast_node *func_ast
= (struct bshell_func_ast_node *)src;
bshell_function *func
= bshell_function_create(func_ast->n_name->tok_str);
if (!func) {
return BSHELL_ERR_NO_MEMORY;
}
fx_queue_entry *cur = fx_queue_first(&func_ast->n_params);
while (cur) {
struct bshell_var_ast_node *var_ast = fx_unbox(
struct bshell_var_ast_node,
cur,
n_base.n_entry);
bshell_function_add_positional_parameter(
func,
var_ast->n_ident->tok_str);
cur = fx_queue_next(cur);
}
bshell_scriptblock *body = bshell_function_get_body(func);
enum bshell_status status = bshell_compile(func_ast->n_body, body);
if (status != BSHELL_SUCCESS) {
bshell_function_unref(func);
return status;
}
*out = func;
return BSHELL_SUCCESS;
}