Commit aa54197d authored by abenoit's avatar abenoit
Browse files

cur_command free for invalid input

parent 335ebabd
......@@ -33,7 +33,8 @@ int handle_pipe(t_command *cur_command, t_xe *xe, int fd_in, int proc)
{
child_setup(fd, fd_in);
ret = execute_cmd(cur_command->args, cur_command->redir_paths, cur_command->redir_types, xe);// error
return (CLEAN_EXIT);
free_command(cur_command);
return (CHILD_EXIT);
}
else
{
......@@ -56,6 +57,7 @@ int parent_pipe_end(t_command *cur_command, t_xe *xe, int fd_in, int proc)
close(fd_in);
}
ret = execute_cmd(cur_command->args, cur_command->redir_paths, cur_command->redir_types, xe);// error
free_command(cur_command);
dup2(xe->backup_stdout, STDOUT_FILENO);
dup2(xe->backup_stdin, STDIN_FILENO);
i = 0;
......@@ -101,16 +103,15 @@ int handle_execution(t_xe *xe, int fd_in, int proc)
cur_command = parse_one_command(xe);
if (cur_command == NULL)
return (MALLOC_ERR);
(void)fd_in;
(void)proc;
// if (cur_command->args != NULL)
// {
// return (handle_command(cur_command, xe, fd_in, proc));
// }
// else
// {
// dup2(xe->backup_stdout, STDOUT_FILENO);
// dup2(xe->backup_stdin, STDIN_FILENO);
if (cur_command->args != NULL)
{
return (handle_command(cur_command, xe, fd_in, proc));
}
else
{
free_command(cur_command);
dup2(xe->backup_stdout, STDOUT_FILENO);
dup2(xe->backup_stdin, STDIN_FILENO);
return (SUCCESS);
// }
}
}
......@@ -192,6 +192,5 @@ int execute_cmd(char **args, char **redir_paths, enum e_redir_op *redir_types,
ret = command[cmd_code](args, xe);
if (ret >= HOME_NOT_SET)
return (ret);
free_str_array(args);
return (ret);
}
......@@ -205,7 +205,7 @@ t_command *parse_one_command(t_xe *xe)
ret = parse_input(&xe->line, xe->env, xe->stat_loc, cur_command);
if (ret == FAILURE)
{
free(cur_command); // et args, redir_paths et types
free_command(cur_command); // et args, redir_paths et types
return (NULL);
}
else if (ret == AMBIG_REDIR)
......
......@@ -204,6 +204,8 @@ void free_command(void *content)
command = (t_command *)content;
free_str_array(command->args);
free_str_array(command->redir_paths);
free(command->redir_types);
free(command);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment