Fix leak.
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 27 Jun 2024 07:34:52 +0000 (09:34 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 27 Jun 2024 07:34:52 +0000 (09:34 +0200)
The handle_input function could be structured better to not make
mistakes such as the one that is fixed by this comment.

inc/minishell.h
src/input_handling.c
src/parsing.c

index b10c13935e546cc715fe7123d0c287c640badae2..a22dd23e58c75c6c2559a8e1cba14a7eae289a81 100644 (file)
@@ -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);
 
index fa87b5b0882d790ff0e57992ecdde909d221bf8c..cfb0caf5945ba29fccf970b133b5d8d8d8417956 100644 (file)
@@ -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);
index c28aa37a69f0bca25baf9f8559fc4dde733fd7e1..02193dd524824956f9a060bf79dfa1a8e7fc058a 100644 (file)
 #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);
 }