From dffb6ea5777276132178639e708531f932a26a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Mon, 1 Apr 2024 18:23:22 +0200 Subject: [PATCH] Resolving the leaks problemes of the path good luck maiboyer --- sources/ft_cmd.c | 4 ++-- sources/ft_exit.c | 15 ++++++++------- sources/main.c | 22 +++++++++++----------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/sources/ft_cmd.c b/sources/ft_cmd.c index 106c56bb..d0acf452 100644 --- a/sources/ft_cmd.c +++ b/sources/ft_cmd.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/01 01:00:30 by rparodi #+# #+# */ -/* Updated: 2024/04/01 01:54:23 by rparodi ### ########.fr */ +/* Updated: 2024/04/01 15:48:48 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,7 @@ void ft_other_cmd(t_utils *shcat, t_usize i) pid_t pid; t_i32 options; - printf("ft_other_cmd = %s", shcat->strs_input[i]); + printf("ft_other_cmd = %s\n", shcat->strs_input[i]); options = 0; pid = fork(); if (pid == -1) diff --git a/sources/ft_exit.c b/sources/ft_exit.c index bcc72f93..710f8007 100644 --- a/sources/ft_exit.c +++ b/sources/ft_exit.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */ -/* Updated: 2024/04/01 01:16:47 by rparodi ### ########.fr */ +/* Updated: 2024/04/01 18:21:22 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,21 +25,22 @@ void ft_free_strs(t_str *strs) free(strs); } - t_str str_input; - t_str *strs_input; - void ft_free_utils(t_utils *s) { + if (s->name_shell) + free(s->name_shell); if (s->str_input) - free(str_input); + free(s->str_input); if (s->strs_input) - ft_free_strs(strs_input); + ft_free_strs(s->strs_input); + if (s->path) + ft_free_strs(s->path); free(s); } void ft_exit(t_utils *maiboyerlpb, t_u8 exit_status) { - if (maiboyerlpb) + if (maiboyerlpb != NULL) ft_free_utils(maiboyerlpb); printf("exit\n"); exit(exit_status); diff --git a/sources/main.c b/sources/main.c index 9af5af1d..68957f4a 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */ -/* Updated: 2024/04/01 01:51:47 by rparodi ### ########.fr */ +/* Updated: 2024/04/01 18:17:41 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,9 +62,11 @@ void ft_check(t_utils *shcat, char **input) else { if (ft_strcmp(input[i], "exit") == 0) - ft_exit(NULL, 0); + ft_exit(shcat, 0); else if (ft_strcmp(input[i], "pwd") == 0) ft_pwd(); + else if (ft_strcmp(input[i], "cmd") == 0) + ft_echo("ECHO MAIS PAS ARG BORDEL !\n", "flag"); else ft_other_cmd(shcat, i); } @@ -74,18 +76,16 @@ void ft_check(t_utils *shcat, char **input) void ft_take_args(t_utils *shcat) { - t_i32 i; - t_str user_input = NULL; - t_str *args = NULL; + t_i32 i; i = 0; while (1) { - shcat->str_input = readline(shcat->name_shell); - if (!user_input) + shcat->str_input = readline((t_const_str)shcat->name_shell); + if (!shcat->str_input) ft_exit(shcat, 0); - shcat->strs_input = ft_split(user_input, ' '); - if (!args) + shcat->strs_input = ft_split(shcat->str_input, ' '); + if (!shcat->strs_input) exit(1); ft_check(shcat, shcat->strs_input); add_history(shcat->str_input); @@ -124,12 +124,12 @@ t_i32 main(t_i32 argc, t_str argv[], t_str arge[]) { t_utils *shcat; - shcat = (t_utils *)malloc(sizeof(t_utils)); + shcat = (t_utils *)ft_calloc(sizeof(t_utils), 1); if (argc == 2) shcat->name_shell = ft_strdup(strcat(argv[1], " > ")); else shcat->name_shell = ft_strdup("shcat > "); - ft_init_arge(arge, shcat); shcat->envp = arge; + ft_init_arge(arge, shcat); ft_take_args(shcat); }