fix leak mini inception and no path

This commit is contained in:
kinou-p 2022-04-19 07:20:37 +02:00
parent fa522d064f
commit 0d69254798
5 changed files with 27 additions and 16 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/18 15:19:51 by apommier ### ########.fr */
/* Updated: 2022/04/19 06:46:37 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -47,6 +47,8 @@ char **ft_dup_double(char **env)
int i;
i = 0;
if (!env)
return (0);
while (env[i])
i++;
new_tab = ft_calloc(sizeof(char *), i + 1);
@ -90,8 +92,8 @@ void print_prompt(char **path)
free_double(path);
exit_shell(cmd, 0);
}
add_history(input);
if (ft_strlen(input) && next_space(input, 0) && input)
add_history(input);
if (ft_strlen(input) && next_space(input, 0) && input && path)
{
cmd = set_cmd(input, path, err_var);
//path = ft_dup_double(path);
@ -129,6 +131,7 @@ int main(int ac, char **av, char **path)
printf("Not today\n");
return (0);
}
//print_double_fd(path, 1);
env = ft_dup_double(path);
av = 0;
if (ac != 1)
@ -136,7 +139,7 @@ int main(int ac, char **av, char **path)
ft_putstr_fd("Error: too much arguments\n", 2);
return (0);
}
printf("---MINISHELL START---\n");
printf("---MINISHELL START---\n");
signal(SIGINT, crtl_c);
//signal(SIGQUIT, sig_quit);
print_prompt(env);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/02 18:51:31 by apommier #+# #+# */
/* Updated: 2022/04/18 06:32:01 by apommier ### ########.fr */
/* Updated: 2022/04/19 07:01:19 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -89,7 +89,7 @@ void exec_cmd(t_cmd *cmd, char **env, int *fdpipe)
if (!cmd->current_s_cmd->cmd || access(cmd->current_s_cmd->cmd, F_OK))
{
ft_putstr_fd("Minishell: command not found: ", 2);
ft_putstr_fd(cmd->current_s_cmd->cmd + 1, 2);
ft_putstr_fd(cmd->current_s_cmd->cmd, 2);
ft_putstr_fd("\n", 2);
close(0);
close(1);
@ -124,8 +124,8 @@ void execute(t_cmd *cmd, char **env)
int tmpout = -1;
int i;
tmpin = -1;
tmpout = -1;
i = 0;
fdpipe[1] = -1;
tmpin = dup(0);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 16:58:40 by apommier #+# #+# */
/* Updated: 2022/04/10 21:07:05 by apommier ### ########.fr */
/* Updated: 2022/04/19 07:01:35 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -49,6 +49,11 @@ char *does_access(char **path, char **exec)
char *cmd;
char *swap;
// if (!path)
// {
// ft_putstr_fd("Minishell: no PATH\n", 2);
// return (0);
// }
swap = 0;
cmd = 0;
i = 0;
@ -76,17 +81,15 @@ char *get_command(char **exec, char **path)
char *swap;
swap = 0;
if (!path)
return (0);
if ((exec[0][0] == '/' || exec[0][0] == '.') && !access(exec[0], F_OK))
{
//free_double(path);
return (exec[0]);
}
else if (exec[0][0] == '/')
{
printf("BAD PATH FOR CMD\n");
//free_double(path);
return(0);
}
swap = does_access(path, exec);
return (swap);
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 12:33:30 by apommier #+# #+# */
/* Updated: 2022/04/17 11:05:04 by apommier ### ########.fr */
/* Updated: 2022/04/19 07:14:17 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,6 +19,7 @@ void exit_shell(t_cmd *cmd, int ret)
i = 0;
//if (cmd)
// free_double(cmd->env);
ft_putstr_fd("exit\n", 1);
if (!cmd)
exit(ret);
if (cmd->tmpin != -1)
@ -38,7 +39,7 @@ void exit_shell(t_cmd *cmd, int ret)
free_cmd(cmd);
clear_history();
//print_double_fd(cmd->s_cmds[0]->env, 1);
ft_putstr_fd("exit\n", 1);
//if (cmd->path)
//free_double(cmd->path);
cmd = 0;

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/09 23:58:21 by apommier #+# #+# */
/* Updated: 2022/04/18 06:43:23 by apommier ### ########.fr */
/* Updated: 2022/04/19 07:09:58 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -230,7 +230,11 @@ int parse_quote(t_cmd *cmd)
if (!is_builtin(cmd->s_cmds[i]->args[0]))
cmd->s_cmds[i]->cmd = get_command(cmd->s_cmds[i]->args, cmd->path);
else
cmd->s_cmds[i]->cmd = cmd->s_cmds[i]->args[0];
if (!cmd->s_cmds[i]->cmd)
cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->args[0]);
else
cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->cmd);
//free(cmd->s_cmds[i]->cmd);
//cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->args[0]);
//printf("parse quote -%s-\n", cmd->s_cmds[i]->cmd);