mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 11:26:51 +01:00
「🔨」 fix: Fixed some leak in the heredoc
This commit is contained in:
@ -39,4 +39,7 @@ void free_redir(void *redir_v);
|
|||||||
void free_token(void *token_v);
|
void free_token(void *token_v);
|
||||||
void free_cmd(void *content);
|
void free_cmd(void *content);
|
||||||
|
|
||||||
|
t_env **get_env(t_env **env);
|
||||||
|
t_list **get_list(t_list **list);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/20 09:19:39 by mmoussou #+# #+# */
|
/* 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));
|
return (-(status == -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_heredoc(char *delimiter)
|
int __heredoc(char *delimiter)
|
||||||
{
|
{
|
||||||
int fork_pid;
|
int fork_pid;
|
||||||
int fd;
|
int fd;
|
||||||
@ -95,9 +95,20 @@ int ft_heredoc(char *delimiter)
|
|||||||
if (!fork_pid)
|
if (!fork_pid)
|
||||||
{
|
{
|
||||||
get_input(delimiter, fd);
|
get_input(delimiter, fd);
|
||||||
|
ft_envclear(get_env(NULL), free);
|
||||||
|
ft_lstclear(get_list(NULL), &free_token);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
waitpid(fork_pid, NULL, 0);
|
waitpid(fork_pid, NULL, 0);
|
||||||
return (fd_manager(1));
|
return (fd_manager(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ft_heredoc(char *delimiter)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = __heredoc(delimiter);
|
||||||
|
|
||||||
|
return (fd);
|
||||||
|
}
|
||||||
|
32
src/get_to_free.c
Normal file
32
src/get_to_free.c
Normal 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);
|
||||||
|
}
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
/* 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;
|
rl = NULL;
|
||||||
get_program_name(av[0]);
|
get_program_name(av[0]);
|
||||||
env_l = env_init(env);
|
env_l = env_init(env);
|
||||||
|
get_env(&env_l);
|
||||||
if (!env_l)
|
if (!env_l)
|
||||||
return (EXIT_FAILURE);
|
return (EXIT_FAILURE);
|
||||||
signal(SIGINT, &sig_c);
|
signal(SIGINT, &sig_c);
|
||||||
@ -62,6 +63,7 @@ int main(int ac, char **av, char **env)
|
|||||||
continue ;
|
continue ;
|
||||||
}
|
}
|
||||||
piped = tokenizer(rl);
|
piped = tokenizer(rl);
|
||||||
|
get_list(&piped);
|
||||||
if (check_argv(piped))
|
if (check_argv(piped))
|
||||||
continue ;
|
continue ;
|
||||||
add_history(rl);
|
add_history(rl);
|
||||||
|
Reference in New Issue
Block a user