fix potential memory leak in cmdlist_from_wordlist

This leak would happen if the alocation of the builder fails. In that case, we
don't free our copy of the wordlist
This commit is contained in:
Khaïs COLIN 2025-03-20 12:23:54 +01:00
parent bed8c9d507
commit 73a64b2ec3
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 17:49:46 by khais #+# #+# */ /* Created: 2025/02/24 17:49:46 by khais #+# #+# */
/* Updated: 2025/03/19 16:43:14 by khais ### ########.fr */ /* Updated: 2025/03/20 12:23:39 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -81,7 +81,7 @@ t_cmdlist *cmdlist_from_wordlist(const t_wordlist *wordlist)
if (words == NULL) if (words == NULL)
return (NULL); return (NULL);
if (setup_cmdlist_builder(&builder, &words) == NULL) if (setup_cmdlist_builder(&builder, &words) == NULL)
return (NULL); return (wordlist_destroy(words), NULL);
while (builder.error == false && builder.current_word != NULL) while (builder.error == false && builder.current_word != NULL)
{ {
if (match_op(builder.current_word->word) == OP_INVALID) if (match_op(builder.current_word->word) == OP_INVALID)