🔨」 fix: Fixed some leak in the heredoc

This commit is contained in:
2024-07-09 18:06:35 +02:00
parent 4b80fef3f3
commit b1f77b386a
4 changed files with 51 additions and 3 deletions

View File

@ -39,4 +39,7 @@ void free_redir(void *redir_v);
void free_token(void *token_v);
void free_cmd(void *content);
t_env **get_env(t_env **env);
t_list **get_list(t_list **list);
#endif

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 09:19:39 by mmoussou #+# #+# */
/* Updated: 2024/07/09 11:05:31 by adjoly ### ########.fr */
/* Updated: 2024/07/09 18:02:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -74,7 +74,7 @@ static int get_input(char *delimiter, int fd)
return (-(status == -1));
}
int ft_heredoc(char *delimiter)
int __heredoc(char *delimiter)
{
int fork_pid;
int fd;
@ -95,9 +95,20 @@ int ft_heredoc(char *delimiter)
if (!fork_pid)
{
get_input(delimiter, fd);
ft_envclear(get_env(NULL), free);
ft_lstclear(get_list(NULL), &free_token);
exit(0);
}
else
waitpid(fork_pid, NULL, 0);
return (fd_manager(1));
}
int ft_heredoc(char *delimiter)
{
int fd;
fd = __heredoc(delimiter);
return (fd);
}

32
src/get_to_free.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_to_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/09 17:24:15 by adjoly #+# #+# */
/* Updated: 2024/07/09 18:05:07 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "env.h"
#include "libft.h"
t_env **get_env(t_env **env)
{
static t_env **ret;
if (env)
ret = env;
return (ret);
}
t_list **get_list(t_list **list)
{
static t_list **ret;
if (list)
ret = list;
return (ret);
}

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
/* Updated: 2024/07/09 16:41:08 by adjoly ### ########.fr */
/* Updated: 2024/07/09 18:04:47 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -46,6 +46,7 @@ int main(int ac, char **av, char **env)
rl = NULL;
get_program_name(av[0]);
env_l = env_init(env);
get_env(&env_l);
if (!env_l)
return (EXIT_FAILURE);
signal(SIGINT, &sig_c);
@ -62,6 +63,7 @@ int main(int ac, char **av, char **env)
continue ;
}
piped = tokenizer(rl);
get_list(&piped);
if (check_argv(piped))
continue ;
add_history(rl);