From 67bf858a494f008a99f542ab662aeb081ba62f90 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 25 Jun 2024 15:30:03 +0200 Subject: [PATCH] fix: free value returned by readline --- dev/TODO | 1 - src/parse_command.c | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dev/TODO b/dev/TODO index 8bfd15b..259fbd6 100644 --- a/dev/TODO +++ b/dev/TODO @@ -10,7 +10,6 @@ - exit (with no options) - fix - empty variables aren't freed - - need to free value returned by readline - the builtins should get all arguments and check if they're good - command `echo "hello` with unclosed quotes diff --git a/src/parse_command.c b/src/parse_command.c index f305f1b..eb49b3c 100644 --- a/src/parse_command.c +++ b/src/parse_command.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/24 13:47:40 by mcolonna #+# #+# */ -/* Updated: 2024/06/25 13:06:57 by mcolonna ### ########.fr */ +/* Updated: 2024/06/25 15:28:41 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,7 +57,8 @@ static int heredoc(t_memclass mc, int *readfd, const char *eof) { const t_memclass mc_in = mem_subclass(fatal_error, mc); int outpipe[2]; - t_const_string line; + char *line; + char *to_free; const t_const_string eof_line = str_join(fatal_error, mc_in, eof, "\n"); if (pipe(outpipe) == -1) @@ -66,12 +67,14 @@ static int heredoc(t_memclass mc, int *readfd, const char *eof) while (true) { line = cool_readline("\e[38;5;33m( 'o')> \e[0m"); + to_free = line; if (!line) line = ""; if (str_eq(line, eof) || str_eq(line, eof_line)) break ; print_str(err_remember, outpipe[1], line); print_str(err_remember, outpipe[1], "\n"); + free(to_free); if (err_get()) return (minishell_error("errno"), errno); }