From 8882929423b88765ed937e2a2ea6cd4b7c7703a7 Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 12 Feb 2026 03:09:45 +0100 Subject: [PATCH] update: command list is now freed completely if any error ocurrs --- include/parser.h | 8 ++++---- src/parser/parser.c | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/parser.h b/include/parser.h index 60cba1d..b89c2a2 100644 --- a/include/parser.h +++ b/include/parser.h @@ -6,7 +6,7 @@ /* By: sede-san type == TOKEN_WORD) { ft_lstadd_back(&args, ft_lstnew(ft_strdup(token->value))); - command->argc++; + (*command)->argc++; arg = arg->next; if (arg != NULL) token = (t_token *)arg->content; } *tokens = arg; - command->argv = args_to_array(args, command->argc); + (*command)->argv = args_to_array(args, (*command)->argc); ft_lstclear_nodes(&args); } void redirection_add( t_list **tokens, t_token *token, - t_command *command + t_command **command ) { t_redirection *redirection; @@ -268,7 +268,11 @@ void redirection_add( redirection = redirection_new(tokens); if (redirection == NULL) + { + command_clear(*command); + *command = NULL; return ; + } redirection_tokens = ft_lstnew(redirection); if (redirection_tokens == NULL) { @@ -276,9 +280,9 @@ void redirection_add( return (malloc_error()); } if (token->type == TOKEN_HEREDOC) - ft_lstadd_back(&command->heredocs, redirection_tokens); + ft_lstadd_back(&(*command)->heredocs, redirection_tokens); else - ft_lstadd_back(&command->redirections, redirection_tokens); + ft_lstadd_back(&(*command)->redirections, redirection_tokens); } /**