From 9322ec9ec95556dedfdb80ceab75de95bef19ce8 Mon Sep 17 00:00:00 2001 From: LuckyLaszlo Date: Fri, 10 Dec 2021 06:34:44 +0100 Subject: [PATCH] close_stdio() at exit --- headers/minishell_prototypes.h | 1 + srcs/free.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/headers/minishell_prototypes.h b/headers/minishell_prototypes.h index 4e2fcee..20ff829 100644 --- a/headers/minishell_prototypes.h +++ b/headers/minishell_prototypes.h @@ -66,6 +66,7 @@ int builtin_echo(int argc, char *argv[], t_all *c); int exit_free(t_all *c, int exit_status); void free_pipeline(t_cmd **pipeline_ptr[]); void close_pipeline_fd(t_cmd *pipeline[]); +void close_stdio(void); typedef void (*t_free_f)(void *); // generic // Error wrappers diff --git a/srcs/free.c b/srcs/free.c index 285350b..303a182 100644 --- a/srcs/free.c +++ b/srcs/free.c @@ -23,6 +23,7 @@ int exit_free(t_all *c, int exit_status) //if (c->termios_changed) // tcsetattr(STDIN_FILENO, TCSANOW, &c->ori_termios); rl_clear_history(); + close_stdio(); exit(exit_status); } @@ -70,3 +71,13 @@ void close_pipeline_fd(t_cmd *pipeline[]) i++; } } + +void close_stdio(void) +{ + if (close(STDIN_FILENO) == -1) + perror("close()"); + if (close(STDOUT_FILENO) == -1) + perror("close()"); + if (close(STDERR_FILENO) == -1) + perror("close()"); +}