fixed here_doc but lots of leaks

This commit is contained in:
mdev9
2024-03-25 13:03:23 +01:00
parent eb5f2bd32e
commit 1f567bd6ce
3 changed files with 18 additions and 10 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */
/* Updated: 2024/03/24 18:41:32 by marde-vr ### ########.fr */
/* Updated: 2024/03/25 12:57:12 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,18 +22,16 @@ char *get_tmp_file_name(t_msh *msh)
i = 0;
tmp_file_name = ".tmp";
i_char = ft_itoa(i);
res = ft_strjoin(tmp_file_name, i_char);
res = ft_strjoin_free(tmp_file_name, i_char, 2);
if (!res)
ft_exit(msh, 1);
free(i_char);
while (!access(res, F_OK))
{
free(res);
i_char = ft_itoa(i);
res = ft_strjoin(tmp_file_name, i_char);
res = ft_strjoin_free(tmp_file_name, i_char, 2);
if (!res)
ft_exit(msh, 1);
free(i_char);
i++;
}
return (res);
@ -75,7 +73,6 @@ void get_here_doc_input(t_msh *msh, char *eof)
write(msh->in_fd, line, ft_strlen(line));
write(msh->in_fd, "\n", 1);
}
free(eof);
free(line);
}
@ -96,15 +93,20 @@ void handle_here_doc(t_msh *msh, char *eof)
{
get_here_doc_input(msh, eof);
close(msh->in_fd);
free(here_doc_file);
ft_exit(msh, 0);
//exit(0);
}
else
{
wait(0);
waitpid(pid, 0 , 0);
close(msh->in_fd);
msh->in_fd = open(here_doc_file, O_RDWR, 0644);
free(here_doc_file);
if (msh->in_fd == -1)
{
perror("open");
ft_printf_fd(2, "exiting\n");
ft_exit(msh, 1);
}
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
/* Updated: 2024/02/21 23:12:34 by marde-vr ### ########.fr */
/* Updated: 2024/03/25 12:45:39 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,9 +36,16 @@ void free_cmd(t_cmd *cmd)
if (cmd)
{
if (cmd && cmd->token)
{
free(cmd->token);
cmd->token = 0;
}
if (cmd && cmd->next)
{
free_cmd(cmd->next);
cmd->next = 0;
}
free(cmd);
cmd = 0;
}
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
/* Updated: 2024/03/25 12:34:39 by tomoron ### ########.fr */
/* Updated: 2024/03/25 13:01:29 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -76,7 +76,6 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
(void)argc;
(void)argv;
(*msh)->env = get_env(envp);
(*msh)->aliases = 0;
signal(SIGINT, signal_handler_interactive);
signal(SIGQUIT, signal_handler_interactive);
return (0);