fix leak fds

This commit is contained in:
kinou-p 2022-04-17 02:19:04 +02:00
parent d413fed41c
commit 72d7d2ebbf
4 changed files with 18 additions and 9 deletions

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
/* Updated: 2022/04/16 13:54:16 by apommier ### ########.fr */
/* Updated: 2022/04/17 02:13:41 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -95,6 +95,11 @@ int main(int ac, char **av, char **path)
{
char **env;
if (!isatty(0))
{
printf("Not today\n");
return (0);
}
env = ft_dup_double(path);
av = 0;
if (ac != 1)

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/02 18:51:31 by apommier #+# #+# */
/* Updated: 2022/04/16 16:14:43 by apommier ### ########.fr */
/* Updated: 2022/04/17 02:09:44 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -178,9 +178,9 @@ void execute(t_cmd *cmd, char **env)
fdin=fdpipe[0];
exec_cmd(cmd, env, fdpipe);
close(cmd->current_s_cmd->fd[0]);
close(fdin);
//close(fdin); //bad thing
}
if (fdpipe[1] > 0)
if (fdpipe[1] != -1)
close(fdpipe[1]);
i++;
cmd->current_s_cmd = cmd->s_cmds[i];
@ -188,8 +188,8 @@ void execute(t_cmd *cmd, char **env)
}
close_pipe(cmd);
dup2(tmpin, 0);
close(tmpin);
dup2(tmpout, 1);
close(tmpin);
close(tmpout);
wait_exit(cmd);
//close(tmpin);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 12:33:30 by apommier #+# #+# */
/* Updated: 2022/04/16 16:13:46 by apommier ### ########.fr */
/* Updated: 2022/04/17 02:11:56 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,6 +29,10 @@ void exit_shell(t_cmd *cmd, int ret)
dup2(cmd->tmpout, 1);
close(cmd->tmpout);
}
if (cmd->current_s_cmd->fd[0] != -1)
close(cmd->current_s_cmd->fd[0]);
if (cmd->current_s_cmd->fd[1] != -1)
close(cmd->current_s_cmd->fd[1]);
free_cmd(cmd);
clear_history();
//print_double_fd(cmd->s_cmds[0]->env, 1);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */
/* Updated: 2022/04/16 16:11:37 by apommier ### ########.fr */
/* Updated: 2022/04/17 02:08:41 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,8 +25,8 @@ t_s_cmd *set_s_cmd(char *line, int index)
s_cmd = malloc(sizeof(t_s_cmd));
if (!s_cmd)
return (0);
//s_cmd->infile = 0;
//s_cmd->outfile = 0;
s_cmd->fd[0] = -1;
s_cmd->fd[1] = -1;
s_cmd->args = 0;
s_cmd->infile = 0;
s_cmd->outfile = 0;