fix leak 24121235

This commit is contained in:
kinou-p 2022-04-19 10:39:41 +02:00
parent 568213dea4
commit 13ab6456d0
9 changed files with 72 additions and 42 deletions

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 22:33:49 by apommier #+# #+# */
/* Updated: 2022/04/18 15:39:06 by apommier ### ########.fr */
/* Updated: 2022/04/19 08:37:43 by apommier ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,17 +6,17 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:09:17 by apommier #+# #+# */
/* Updated: 2022/01/18 06:50:22 by apommier ### ########.fr */
/* Updated: 2022/04/19 08:44:19 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
long ft_atoi(const char *nptr)
long long ft_atoi(const char *nptr)
{
int i;
long nbr;
long minus;
long long nbr;
long long minus;
minus = 1;
nbr = 0;

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/11 03:21:27 by apommier #+# #+# */
/* Updated: 2022/02/14 00:27:42 by apommier ### ########.fr */
/* Updated: 2022/04/19 08:44:37 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -48,7 +48,7 @@ size_t ft_strlcpy(char *dst, const char *src, size_t size);
size_t ft_strlcat(char *dst, const char *src, size_t size);
char *ft_strjoin(char *save, char *s2);
char *ft_strnstr(const char *big, const char *little, size_t len);
long ft_atoi(const char *nptr);
long long ft_atoi(const char *nptr);
void *ft_calloc(size_t nmenb, size_t size);
char *ft_strdup(const char *s);

View File

@ -6,18 +6,30 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/15 11:23:32 by apommier #+# #+# */
/* Updated: 2022/04/16 02:19:58 by apommier ### ########.fr */
/* Updated: 2022/04/19 09:04:57 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/minishell.h"
int max_long(char *nbr)
{
printf("%s\n", nbr);
if (ft_strlen(nbr) > 19)
return (1);
if (ft_atoi(nbr) > 9223372036854775800 && nbr[ft_strlen(nbr) - 1] > '7')
return (1);
if (ft_atoi(nbr) < -9223372036854775800 && nbr[ft_strlen(nbr) - 1] > '8')
return (1);
printf("return 0\n");
return (0);
}
void ft_exit(t_s_cmd *cmd)
{
int i;
i = -1;
//printf("nb_args= %d\n", cmd->nb_args);
if (cmd->nb_args > 2)
{
ft_putstr_fd("Minishell: exit: too many arguments\n", 2);
@ -29,13 +41,19 @@ void ft_exit(t_s_cmd *cmd)
}
else if (cmd->nb_args == 1)
exit_shell(cmd->big_cmd, 0);
while (cmd->args[1][++i])
{
if (!ft_isdigit(cmd->args[1][i]) && !(cmd->args[1][i] == '-' && ft_isdigit(cmd->args[1][i + 1])))
if ((!ft_isdigit(cmd->args[1][i]) && !(cmd->args[1][i] == '-' && ft_isdigit(cmd->args[1][i + 1]))))
{
ft_putstr_fd("Minishell: exit: numeric argument required\n", 2);
exit_shell(cmd->big_cmd, 2);
}
}
if (max_long(cmd->args[1]))
{
ft_putstr_fd("Minishell: exit: numeric argument required\n", 2);
exit_shell(cmd->big_cmd, 2);
}
exit_shell(cmd->big_cmd, ft_atoi(cmd->args[1]));
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
/* Updated: 2022/04/19 07:24:47 by apommier ### ########.fr */
/* Updated: 2022/04/19 08:23:56 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,7 +24,7 @@ void crtl_c(int num)
void sig_quit(int num)
{
num = 0;
(void)num;
ft_putstr_fd("\b \b\b \b", 1);
//printf("quit num= %d\n", num);
//exit(0);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/02 18:51:31 by apommier #+# #+# */
/* Updated: 2022/04/19 07:01:19 by apommier ### ########.fr */
/* Updated: 2022/04/19 08:26:07 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -58,8 +58,11 @@ int wait_exit(t_cmd *cmd)
else if (WIFSIGNALED(status))
{
//printf("return by signal cmd = -%s-\n", cmd->s_cmds[i]->cmd);
//printf("signal= %d\n", WTERMSIG(status));
if (WTERMSIG(status) != 13)
cmd->err_var = WTERMSIG(status);
if (WTERMSIG(status) == 3)
ft_putstr_fd("^\\Quit", 1);
//if (cmd->err_var == 2)
ft_putstr_fd("\b\b\b\b\b", 1);
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 16:58:40 by apommier #+# #+# */
/* Updated: 2022/04/19 07:01:35 by apommier ### ########.fr */
/* Updated: 2022/04/19 08:09:11 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -70,7 +70,7 @@ char *does_access(char **path, char **exec)
swap = ft_strjoin(swap, exec[0]);
free(cmd);
}
//if (path[i])
if (path[i])
return (swap);
free(swap);
return (0);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */
/* Updated: 2022/04/18 15:44:32 by apommier ### ########.fr */
/* Updated: 2022/04/19 09:59:04 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -42,22 +42,6 @@ t_s_cmd *set_s_cmd(char *line, int index)
return (0);
}
split_line = ft_split_with_quote(line, ' ');
//parse_quote(cmd);
//print_double_fd(split_line, 0);
/*if (!is_builtin(split_line[0]))
s_cmd->cmd = ft_strdup(get_command(split_line, cmd->path));
else
s_cmd->cmd = ft_strdup(split_line[0]);*/
/*if (!s_cmd->cmd)
{
free(line);
free_double(split_line);
free(s_cmd);
return (0);
}*/
s_cmd->nb_args = double_size(split_line);
s_cmd->args = split_line;
free(line);
@ -117,6 +101,7 @@ t_cmd *set_cmd(char *input, char **env, int nb)
cmds = ft_split_with_quote(input, '|');
if (!cmds)
return (0);
cmd = malloc(sizeof(t_cmd));
if (!cmd)
return (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/19 07:09:58 by apommier ### ########.fr */
/* Updated: 2022/04/19 10:37:55 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -94,9 +94,11 @@ char *del_char(char *str, int *index)
// swap =
//printf("in del char after dup -%s-\n", swap);
// if (str)
str[*index] = 0;
str[*index] = 0;
swap2 = str;
str = ft_strjoin(str, swap);
free(swap2);
free(swap);
//if (*index)
// (*index)--;
//printf("after del char -%s-\n", str);
@ -164,10 +166,13 @@ char *set_var(t_cmd *big_cmd, char *cmd)
i = 0;
while (cmd[i])
{
//printf("set var str= %s et i= %d\n", cmd, i);
//printf("char= -%c-\n", cmd[i]);
if (cmd[i] == '\'')
{
//del = cmd;
cmd = del_char(cmd, &i);
//free(del);
//printf("i= %d char= -%c- str= -%s-\n", i, cmd[i], cmd);
if (cmd[i])
{
@ -180,7 +185,10 @@ char *set_var(t_cmd *big_cmd, char *cmd)
}
else if (cmd[i] == '"')
{
//del = cmd;
cmd = del_char(cmd, &i);
//free(del);
//printf("cmd after del char= %s\n", cmd);
//printf("i= %d char= -%c-\n", i, cmd[i]);
if (cmd[i])
{
@ -193,11 +201,14 @@ char *set_var(t_cmd *big_cmd, char *cmd)
}
i++;
}
del = cmd;
//del = cmd;
//printf("cmd before del char2= %s\n", cmd);
cmd = del_char(cmd, &i);
free(cmd);
//printf("cmd after del char2= %s\n", cmd);
//free(del);
}
//printf("cmd after \"= %s\n", cmd);
//printf("i= %d char= -%c-\n", i, cmd[i]);
//i++;
}
else if (cmd[i] == '$')
@ -218,23 +229,36 @@ int parse_quote(t_cmd *cmd)
i = 0;
while (cmd->s_cmds[i])
{
j = -1;
//print_double_fd(cmd->s_cmds[i]->args, 1);
while (cmd->s_cmds[i]->args[++j])
{
//printf("parse quote args= -%s-\n", cmd->s_cmds[i]->args[j]);
swap = cmd->s_cmds[i]->args[j];
cmd->s_cmds[i]->args[j] = set_var(cmd, cmd->s_cmds[i]->args[j]);
if (cmd->s_cmds[i]->args[j] != swap)
free(swap);
//if (cmd->s_cmds[i]->args[j] != swap)
// free(swap);
}
//printf("parse quote -%s-\n", cmd->s_cmds[i]->args[0]);
if (!is_builtin(cmd->s_cmds[i]->args[0]))
{
cmd->s_cmds[i]->cmd = get_command(cmd->s_cmds[i]->args, cmd->path);
if (cmd->s_cmds[i]->cmd == cmd->s_cmds[i]->args[0])
cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->cmd);
}
else
cmd->s_cmds[i]->cmd = cmd->s_cmds[i]->args[0];
cmd->s_cmds[i]->cmd = ft_strdup(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);
// else
// {
// swap = cmd->s_cmds[i]->cmd;
// cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->cmd);
// free(swap)
// }
//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);