mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「🔨」 fix: leak from heredoc
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/29 13:20:22 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/08/06 17:00:05 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/08/13 13:44:32 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -51,7 +51,7 @@ void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec);
|
||||
*
|
||||
* @return (int) fd of a file containing the user's input, or -1 on error
|
||||
*/
|
||||
int ft_heredoc(char *delimiter);
|
||||
int ft_heredoc(char *delimiter, t_list *list);
|
||||
int __open_fd_here(char *path, int mode);
|
||||
void ft_lstclear_till_nxt(t_list **lst, void (*del)(void *));
|
||||
int get_fd_heredoc(int in);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
|
||||
/* Updated: 2024/08/10 17:54:27 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/08/13 13:45:37 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -164,7 +164,7 @@ t_list *__split_pipe(char *readline);
|
||||
t_list *tokenizer(char *readline, t_env *env);
|
||||
|
||||
t_redir_sign __to_redir_sign(char *redir_sign);
|
||||
t_redir *__open_heredoc(char *filename);
|
||||
t_redir *__open_heredoc(char *filename, t_list *list);
|
||||
t_redir *__to_redir(char *filename, t_redir_sign sign);
|
||||
void __get_fd(t_list *list, t_cmd *cmd);
|
||||
char **__get_argv(char **content);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/20 09:19:39 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/08/10 12:42:44 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/08/13 13:49:14 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -73,19 +73,20 @@ static int get_input(char *delimiter, int fd)
|
||||
return (-(status == -1));
|
||||
}
|
||||
|
||||
void __forked(char *delimiter, int fd)
|
||||
void __forked(char *delimiter, int fd, t_list *list)
|
||||
{
|
||||
ft_lstclear(&list, free_redir);
|
||||
signal(SIGINT, &__heredoc_sig);
|
||||
get_input(delimiter, fd);
|
||||
ft_free("a", (char ***)get_void(NULL));
|
||||
ft_envclear(get_env(NULL), free);
|
||||
ft_lstclear(get_list(NULL), free);
|
||||
ft_lstclear(get_list2(NULL), free_cmd);
|
||||
ft_free("a", (char ***)get_void(NULL));
|
||||
rl_clear_history();
|
||||
close(fd);
|
||||
}
|
||||
|
||||
int __heredoc(char *delimiter)
|
||||
int __heredoc(char *delimiter, t_list *list)
|
||||
{
|
||||
int fork_pid;
|
||||
int fd;
|
||||
@ -106,7 +107,7 @@ int __heredoc(char *delimiter)
|
||||
}
|
||||
if (!fork_pid)
|
||||
{
|
||||
__forked(delimiter, fd);
|
||||
__forked(delimiter, fd, list);
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
@ -114,10 +115,10 @@ int __heredoc(char *delimiter)
|
||||
return (check_error(heredoc_ret, fd));
|
||||
}
|
||||
|
||||
int ft_heredoc(char *delimiter)
|
||||
int ft_heredoc(char *delimiter, t_list *list)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = __heredoc(delimiter);
|
||||
fd = __heredoc(delimiter, list);
|
||||
return (fd);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/10 01:14:10 by adjoly #+# #+# */
|
||||
/* Updated: 2024/08/10 12:43:36 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/08/13 13:49:19 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/05 23:31:09 by adjoly #+# #+# */
|
||||
/* Updated: 2024/08/06 15:29:13 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/08/13 13:43:08 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -33,14 +33,14 @@ t_redir_sign __to_redir_sign(char *redir_sign)
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
t_redir *__open_heredoc(char *filename)
|
||||
t_redir *__open_heredoc(char *filename, t_list *list)
|
||||
{
|
||||
int fd;
|
||||
t_redir *redir;
|
||||
|
||||
if (!filename && !*filename)
|
||||
return (NULL);
|
||||
fd = ft_heredoc(filename);
|
||||
fd = ft_heredoc(filename, list);
|
||||
redir = ft_calloc(sizeof(t_redir), 1);
|
||||
if (!redir)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/05 14:19:35 by adjoly #+# #+# */
|
||||
/* Updated: 2024/08/12 16:28:08 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/08/13 13:40:20 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -24,7 +24,7 @@ t_list *__get_redir(char **content)
|
||||
sign = __to_redir_sign(*content);
|
||||
if (sign == HEREDOC)
|
||||
{
|
||||
tmp = ft_lstnew(__open_heredoc(*(content + 1)));
|
||||
tmp = ft_lstnew(__open_heredoc(*(content + 1), list));
|
||||
ft_lstadd_back(&list, tmp);
|
||||
}
|
||||
else if (sign != ERROR)
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/18 20:13:50 by adjoly #+# #+# */
|
||||
/* Updated: 2024/08/10 17:46:54 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/08/13 13:47:48 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -40,11 +40,13 @@ t_list *tokenizer(char *readline, t_env *env)
|
||||
ft_lstadd_back(&cmd,
|
||||
ft_lstnew(__to_cmd(split_argv(env_var_replace(tmp->content,
|
||||
env)))));
|
||||
if (((t_cmd *)ft_lstlast(cmd)->content)->infile == -2)
|
||||
if (!cmd)
|
||||
return (clear_all(cmd, piped));
|
||||
if (!ft_lstlast(cmd)->content)
|
||||
return (clear_all(cmd, piped));
|
||||
if (!cmd->next)
|
||||
get_list2(&cmd);
|
||||
if (!ft_lstlast(cmd)->content)
|
||||
if (((t_cmd *)ft_lstlast(cmd)->content)->infile == -2)
|
||||
return (clear_all(cmd, piped));
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
Reference in New Issue
Block a user