fix(here_doc): segfault when C-c

This commit is contained in:
Khaïs COLIN 2025-05-02 14:36:00 +02:00
parent ee10abacab
commit 083a2bb2a2
4 changed files with 10 additions and 9 deletions

View file

@ -17,6 +17,7 @@ LINCLUDE = -L$(LIBFTDIR)
ifeq ($(CFLAGS),) ifeq ($(CFLAGS),)
CFLAGS = -Wall -Wextra -Werror \ CFLAGS = -Wall -Wextra -Werror \
$(DEBUG) \
endif endif
export CFLAGS export CFLAGS

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* here_doc_utils.c :+: :+: :+: */ /* here_doc_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/17 11:50:08 by kcolin #+# #+# */ /* Created: 2025/05/02 14:36:33 by kcolin #+# #+# */
/* Updated: 2025/05/02 12:47:12 by jguelen ### ########.fr */ /* Updated: 2025/05/02 14:36:33 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -48,7 +48,6 @@ char *finalize(int outfd, char *filename)
int interupted(int outfd, char *filename) int interupted(int outfd, char *filename)
{ {
ft_printf("\n");
close(outfd); close(outfd);
unlink(filename); unlink(filename);
free(filename); free(filename);

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/09 16:53:02 by kcolin #+# #+# */ /* Created: 2025/04/09 16:53:02 by kcolin #+# #+# */
/* Updated: 2025/04/30 18:00:28 by kcolin ### ########.fr */ /* Updated: 2025/05/02 14:35:54 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,7 +23,8 @@ void redirect_destroy(t_redirect *redirect)
{ {
next = redirect->next; next = redirect->next;
free(redirect->here_doc_eof); free(redirect->here_doc_eof);
if (redirect->type == FT_HEREDOC) if (redirect->type == FT_HEREDOC && redirect->redirectee.filename != NULL
&& redirect->redirectee.filename->word != NULL)
unlink(redirect->redirectee.filename->word); unlink(redirect->redirectee.filename->word);
worddesc_destroy(redirect->redirectee.filename); worddesc_destroy(redirect->redirectee.filename);
free(redirect->unexpanded_filename); free(redirect->unexpanded_filename);

View file

@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/30 10:35/43 by kcolin #+# #+# */ /* Created: 2025/05/02 14:40:34 by kcolin #+# #+# */
/* Updated: 2025/04/30 10:35:43 by kcolin ### ########.fr */ /* Updated: 2025/05/02 14:40:34 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -83,7 +83,7 @@ t_redirect *redir_from_words(t_worddesc *operator,
here_doc(spec, STDIN_FILENO, app), 0, NULL, WORD_TOKEN); here_doc(spec, STDIN_FILENO, app), 0, NULL, WORD_TOKEN);
worddesc_destroy(spec); worddesc_destroy(spec);
if (redir->redirectee.filename == NULL) if (redir->redirectee.filename == NULL)
return (redirect_destroy(redir), ft_errno(FT_EERRNO), NULL); return (redirect_destroy(redir), NULL);
} }
else else
redir->redirectee.filename = specifier; redir->redirectee.filename = specifier;