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);
}
}