fix leak - bad command
This commit is contained in:
parent
e6bba78db6
commit
46b4a154d2
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/09 12:33:30 by apommier #+# #+# */
|
/* Created: 2022/03/09 12:33:30 by apommier #+# #+# */
|
||||||
/* Updated: 2022/03/09 13:58:03 by apommier ### ########.fr */
|
/* Updated: 2022/03/09 16:03:44 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -36,10 +36,15 @@ void free_cmd(t_cmd *cmd)
|
|||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
printf("free_cmd\n");
|
printf("free_cmd\n");
|
||||||
|
|
||||||
while (cmd->s_cmds[i])
|
while (cmd->s_cmds[i])
|
||||||
{
|
{
|
||||||
free_double(cmd->s_cmds[i]->args);
|
free_double(cmd->s_cmds[i]->args);
|
||||||
free(cmd->s_cmds[i]->cmd);
|
free(cmd->s_cmds[i]->cmd);
|
||||||
|
if (cmd->s_cmds[i]->infile)
|
||||||
|
free(cmd->s_cmds[i]->infile);
|
||||||
|
if (cmd->s_cmds[i]->outfile)
|
||||||
|
free(cmd->s_cmds[i]->outfile);
|
||||||
free(cmd->s_cmds[i]);
|
free(cmd->s_cmds[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|||||||
5
main.c
5
main.c
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
|
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
|
||||||
/* Updated: 2022/03/09 14:00:05 by apommier ### ########.fr */
|
/* Updated: 2022/03/09 16:56:38 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -37,6 +37,7 @@ void print_prompt(char **path)
|
|||||||
if (!ft_strcmp("exit", input))
|
if (!ft_strcmp("exit", input))
|
||||||
{
|
{
|
||||||
rl_clear_history();
|
rl_clear_history();
|
||||||
|
free(input);
|
||||||
exit_shell(cmd);
|
exit_shell(cmd);
|
||||||
}
|
}
|
||||||
if (ft_strlen(input))
|
if (ft_strlen(input))
|
||||||
@ -50,6 +51,8 @@ void print_prompt(char **path)
|
|||||||
free_cmd(cmd);
|
free_cmd(cmd);
|
||||||
cmd = 0;
|
cmd = 0;
|
||||||
}
|
}
|
||||||
|
//free_cmd(cmd);
|
||||||
|
//cmd = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/08 16:58:40 by apommier #+# #+# */
|
/* Created: 2022/03/08 16:58:40 by apommier #+# #+# */
|
||||||
/* Updated: 2022/03/09 13:18:04 by apommier ### ########.fr */
|
/* Updated: 2022/03/09 16:45:53 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -81,6 +81,7 @@ char *does_access(char **path, char **exec)
|
|||||||
}
|
}
|
||||||
if (path[i])
|
if (path[i])
|
||||||
return (swap);
|
return (swap);
|
||||||
|
free(swap);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
18
set_cmd.c
18
set_cmd.c
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */
|
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */
|
||||||
/* Updated: 2022/03/09 13:49:49 by apommier ### ########.fr */
|
/* Updated: 2022/03/09 16:58:32 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -29,14 +29,23 @@ t_s_cmd *set_s_cmd(char *line, t_cmd *cmd)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
split_line = ft_split(line, ' ');
|
split_line = ft_split(line, ' ');
|
||||||
s_cmd = malloc(sizeof(t_s_cmd));
|
s_cmd = malloc(sizeof(t_s_cmd));
|
||||||
s_cmd->cmd = get_command(split_line, cmd->path);
|
if (!s_cmd)
|
||||||
if (!s_cmd->cmd)
|
|
||||||
return (0);
|
return (0);
|
||||||
s_cmd->infile = 0;
|
s_cmd->infile = 0;
|
||||||
s_cmd->outfile = 0;
|
s_cmd->outfile = 0;
|
||||||
|
s_cmd->args = 0;
|
||||||
|
//////////////////split_line = set_redirection(s_cmd, line);
|
||||||
|
s_cmd->cmd = get_command(split_line, cmd->path);
|
||||||
|
if (!s_cmd->cmd)
|
||||||
|
{
|
||||||
|
free_double(split_line);
|
||||||
|
free(s_cmd);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
s_cmd->nb_args = double_size(split_line);
|
s_cmd->nb_args = double_size(split_line);
|
||||||
|
//set_redirection(s_cmd);
|
||||||
s_cmd->args = split_line;
|
s_cmd->args = split_line;
|
||||||
return (s_cmd);
|
return (s_cmd);
|
||||||
}
|
}
|
||||||
@ -52,6 +61,7 @@ t_cmd *split_cmd(t_cmd *cmd, char **cmds)
|
|||||||
if (!cmd->s_cmds[i])
|
if (!cmd->s_cmds[i])
|
||||||
{
|
{
|
||||||
printf("invalid command\n");
|
printf("invalid command\n");
|
||||||
|
free_cmd(cmd);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user