From: Lukas Jiriste Date: Thu, 27 Jun 2024 07:34:52 +0000 (+0200) Subject: Fix leak. X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=824da04ce7a45fb63247cb2af1f276fd634e078e;p=42%2Fminishell.git Fix leak. The handle_input function could be structured better to not make mistakes such as the one that is fixed by this comment. --- diff --git a/inc/minishell.h b/inc/minishell.h index b10c139..a22dd23 100644 --- a/inc/minishell.h +++ b/inc/minishell.h @@ -31,7 +31,7 @@ void clean_vars(t_vars *vars); void handle_input(char **line, t_vars *vars); int tokenize(char **line, t_vec *tokens); -int parse(t_vec *tokens, t_tree *parse_tree); +int parse(t_vec *tokens, t_tree **parse_tree); int expand(t_tree *parse_tree, t_vars *vars); int execute(t_tree *parse_tree, t_vars *vars); diff --git a/src/input_handling.c b/src/input_handling.c index fa87b5b..cfb0caf 100644 --- a/src/input_handling.c +++ b/src/input_handling.c @@ -23,7 +23,7 @@ void handle_input(char **input, t_vars *vars) ft_vec_init(&tokens, sizeof(t_token)); parse_tree = NULL; res = tokenize(input, &tokens); - res = res || parse(&tokens, parse_tree); + res = res || parse(&tokens, &parse_tree); res = res || expand(parse_tree, vars); res = res || execute(parse_tree, vars); ft_vec_free(&tokens, free_token); diff --git a/src/parsing.c b/src/parsing.c index c28aa37..02193dd 100644 --- a/src/parsing.c +++ b/src/parsing.c @@ -14,14 +14,14 @@ #include "libft.h" // table should be static or loaded at start and passed in as argument -int parse(t_vec *tokens, t_tree *parse_tree) +int parse(t_vec *tokens, t_tree **parse_tree) { t_parsing_table table; ft_parsing_table_init(&table); ft_parsing_table_load(&table, "shell_parsing_table", "shell_rules"); - parse_tree = ft_parse(tokens, &table); - ft_parse_tree_print(parse_tree); + *parse_tree = ft_parse(tokens, &table); + ft_parse_tree_print(*parse_tree); ft_parsing_table_free(&table); return (0); }