fix(parsing/pipeline): leak when optional pipeline returns NULL

This commit is contained in:
Khaïs COLIN 2025-04-16 18:23:06 +02:00
parent 6cc6e6cfb5
commit 9271b7fa92
3 changed files with 18 additions and 6 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 10:46:28 by khais #+# #+# */ /* Created: 2025/04/15 10:46:28 by khais #+# #+# */
/* Updated: 2025/04/16 15:43:44 by khais ### ########.fr */ /* Updated: 2025/04/17 12:27:05 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,6 +17,7 @@
#include "../redirect/redirect_parse.h" #include "../redirect/redirect_parse.h"
#include "../simple_cmd/simple_cmd_parse.h" #include "../simple_cmd/simple_cmd_parse.h"
#include "../cmd/cmds_parse.h" #include "../cmd/cmds_parse.h"
#include "../cmd/cmd_debug.h"
t_cmd *minishell_group_cmd_parse(t_minishell *app, t_wordlist **tokens) t_cmd *minishell_group_cmd_parse(t_minishell *app, t_wordlist **tokens)
{ {
@ -41,11 +42,14 @@ t_cmd *minishell_group_cmd_parse(t_minishell *app, t_wordlist **tokens)
t_cmd *minishell_group_or_simple_parse(t_minishell *app, t_wordlist **tokens) t_cmd *minishell_group_or_simple_parse(t_minishell *app, t_wordlist **tokens)
{ {
t_cmd *cmd;
if ((*tokens)->word->token_type == OPEN_PARENTH_TOKEN) if ((*tokens)->word->token_type == OPEN_PARENTH_TOKEN)
{ {
worddesc_destroy(wordlist_pop(tokens)); worddesc_destroy(wordlist_pop(tokens));
return (minishell_group_cmd_parse(app, tokens)); cmd = minishell_group_cmd_parse(app, tokens);
} }
else else
return (minishell_simple_cmd_parse(app, tokens)); cmd = minishell_simple_cmd_parse(app, tokens);
return (cmd);
} }

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 11:35:08 by khais #+# #+# */ /* Created: 2025/04/15 11:35:08 by khais #+# #+# */
/* Updated: 2025/04/16 13:07:51 by khais ### ########.fr */ /* Updated: 2025/04/18 09:19:12 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,7 +28,7 @@ t_cmd *minishell_pipeline_parse(t_minishell *app, t_wordlist **tokens)
return (NULL); return (NULL);
opt = minishell_optional_pipeline_parse(app, tokens); opt = minishell_optional_pipeline_parse(app, tokens);
if (!opt && ft_errno_get() != FT_ESUCCESS) if (!opt && ft_errno_get() != FT_ESUCCESS)
return (NULL); return (cmd_destroy(subtree), NULL);
if (!opt) if (!opt)
return (subtree); return (subtree);
while (opt) while (opt)
@ -36,7 +36,8 @@ t_cmd *minishell_pipeline_parse(t_minishell *app, t_wordlist **tokens)
if (connec_reorient_subtree(&pipeline, &subtree, &opt, FT_PIPE) == NULL) if (connec_reorient_subtree(&pipeline, &subtree, &opt, FT_PIPE) == NULL)
{ {
app->last_return_value = 1; app->last_return_value = 1;
return (ft_perror("minishell_pipeline_parse"), NULL); return (cmd_destroy(subtree),
ft_perror("minishell_pipeline_parse"), NULL);
} }
opt = minishell_optional_pipeline_parse(app, tokens); opt = minishell_optional_pipeline_parse(app, tokens);
} }

View file

@ -697,4 +697,11 @@ expecting <<EOF
hello! hello!
EOF EOF
when_run <<EOF "double pipe after echo"
echo | |
EOF
expecting <<"EOF"
minishell: syntax error near unexpected token `|'
EOF
finalize finalize