mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-05 23:18:08 +01:00
redir_parsing: fix memory leak when parsing a redirection with an operator as specifier
if the specifier was not WORD_TOKEN, the operator was not being freed
This commit is contained in:
parent
84a246f6f6
commit
9a32220945
2 changed files with 13 additions and 6 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 10:13:58 by khais #+# #+# */
|
||||
/* Updated: 2025/04/16 13:56:59 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/16 14:10:13 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -29,15 +29,13 @@ t_redirect *minishell_redirect_parse(t_minishell *app, t_wordlist **tokens)
|
|||
while ((*tokens) != NULL && is_redir((*tokens)->word))
|
||||
{
|
||||
redir_operator = wordlist_pop(tokens);
|
||||
if ((*tokens) == NULL)
|
||||
if ((*tokens) != NULL && (*tokens)->word->token_type == WORD_TOKEN)
|
||||
redir_specifier = wordlist_pop(tokens);
|
||||
else
|
||||
{
|
||||
worddesc_destroy(redir_operator);
|
||||
return (ft_errno(FT_EERRNO), redirect_destroy(redir_list), NULL);
|
||||
}
|
||||
if ((*tokens)->word->token_type == WORD_TOKEN)
|
||||
redir_specifier = wordlist_pop(tokens);
|
||||
else
|
||||
return (ft_errno(FT_EERRNO), redirect_destroy(redir_list), NULL);
|
||||
new_redir = redir_from_words(redir_operator, redir_specifier, app);
|
||||
t_redirect_add_back(&redir_list, new_redir);
|
||||
}
|
||||
|
|
|
|||
9
test.sh
9
test.sh
|
|
@ -613,4 +613,13 @@ parsed command
|
|||
╰─ redirections = (empty redir list)
|
||||
EOF
|
||||
|
||||
when_run <<EOF "multiple >"
|
||||
> > > >
|
||||
echo \$?
|
||||
EOF
|
||||
expecting <<"EOF"
|
||||
minishell: syntax error near unexpected token `>'
|
||||
2
|
||||
EOF
|
||||
|
||||
finalize
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue