diff options
| author | Dominik Kaiser | 2025-01-25 15:58:12 +0100 |
|---|---|---|
| committer | GitHub | 2025-01-25 15:58:12 +0100 |
| commit | 3b97eaa0500314866c4a106c77e8f671c9751b89 (patch) | |
| tree | f44fffea0ef290f9bdf79448c90d794ba97b8ca4 /src/parse_cmd.c | |
| parent | bd8c817797d5f2b1affe6957ffc51846a38e70ec (diff) | |
| parent | 8fb5e2839cb7eb7bb72f577577afafcdbdc8a714 (diff) | |
| download | minishell-3b97eaa0500314866c4a106c77e8f671c9751b89.tar.gz minishell-3b97eaa0500314866c4a106c77e8f671c9751b89.zip | |
Merge memory leak fixes
Diffstat (limited to 'src/parse_cmd.c')
| -rw-r--r-- | src/parse_cmd.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/parse_cmd.c b/src/parse_cmd.c index 6505384..578601c 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -6,13 +6,14 @@ /* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */ -/* Updated: 2025/01/20 19:09:21 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 15:00:55 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" static char **collect_args(t_token **tokens, t_env **env); +static void setup_vars(t_token **tokens, t_token **cur, int *i); t_node *parse_cmd(t_token *tokens, t_env **env) { @@ -40,24 +41,29 @@ static char **collect_args(t_token **tokens, t_env **env) int i; t_token *next; - cur = *tokens; - i = 0; + setup_vars(tokens, &cur, &i); while (cur != NULL && ++i) cur = cur->next; result = malloc(sizeof(char *) * (i + 1)); if (result == NULL) return (free_tokens(*tokens), NULL); - cur = *tokens; - i = 0; + setup_vars(tokens, &cur, &i); while (cur != NULL && cur->type == STRING_TOKEN) { next = cur->next; if (cur->previous) - free_token(cur->previous); - result[i] = format_string(cur->content.string, *env, ft_atoi("0")); - i++; + free_token2(cur->previous); + result[i++] = format_string(cur->content.string, *env, ft_atoi("0")); + if (cur->next == NULL) + free_token2(cur); cur = next; } result[i] = NULL; return (result); } + +static void setup_vars(t_token **tokens, t_token **cur, int *i) +{ + *cur = *tokens; + *i = 0; +} |
