fix leak <<

This commit is contained in:
kinou-p 2022-04-18 15:52:11 +02:00
parent 6e4c557f3d
commit fa522d064f
5 changed files with 26 additions and 33 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/16 16:10:54 by apommier ### ########.fr */
/* Updated: 2022/04/18 15:39:06 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -62,6 +62,8 @@ typedef struct s_command {
char **path;
} t_cmd;
char *error_parsing(void);
//main.c
int main();//int ac, char **av, char **path);
char **ft_dup_double(char **env);

View File

@ -14,14 +14,9 @@
char *ft_free(char *save, int *end)
{
if (!*end)
{
free(save);
free(end);
return (0);
}
free(save);
free(end);
return (save);
return (0);
}
char *set_line(char *line, char *save)
@ -75,7 +70,7 @@ char *next_line(char *save, int *end, int fd)
char *get_next_line(int fd)
{
static char *save = NULL;
char *save = NULL;
int *end;
char *line;
@ -84,8 +79,7 @@ char *get_next_line(int fd)
return (0);
end = malloc(sizeof(int *));
*end = 1;
if (save == NULL)
save = ft_calloc(1, 1);
save = ft_calloc(1, 1);
save = next_line(save, end, fd);
line = set_line(line, save);
if (ft_strlen(line) > 0)

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 09:24:25 by apommier ### ########.fr */
/* Updated: 2022/04/18 15:19:51 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -107,14 +107,14 @@ void print_prompt(char **path)
free_cmd(cmd);
cmd = 0;
}
else
/*else
{
/*close(0);
close(0);
close(1);
dup2(tmpin, 0);
dup2(tmpout, 1);*/
dup2(tmpout, 1);
ft_putstr_fd("Minishell: error while parsing command\n", 2);
}
}*/
}
free(input);
}

View File

@ -6,13 +6,17 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */
/* Updated: 2022/04/18 13:22:46 by apommier ### ########.fr */
/* Updated: 2022/04/18 15:44:32 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/minishell.h"
char *error_parsing(void)
{
ft_putstr_fd("Minishell: error while parsing command\n", 2);
return (0);
}
t_s_cmd *set_s_cmd(char *line, int index)
{
@ -47,8 +51,6 @@ t_s_cmd *set_s_cmd(char *line, int index)
else
s_cmd->cmd = ft_strdup(split_line[0]);*/
/*if (!s_cmd->cmd)
{
free(line);
@ -72,7 +74,6 @@ t_cmd *split_cmd(t_cmd *cmd, char **cmds)
cmd->s_cmds[i] = set_s_cmd(cmds[i], i);
if (!cmd->s_cmds[i])
{
printf("no cmd in splitcmd\n");
free_cmd(cmd);
return (0);
}
@ -109,7 +110,10 @@ t_cmd *set_cmd(char *input, char **env, int nb)
char **cmds;
if (!is_quote_good(input) || !is_pipe_good(input))
{
ft_putstr_fd("Minishell: error while parsing command\n", 2);
return (0);
}
cmds = ft_split_with_quote(input, '|');
if (!cmds)
return (0);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 15:18:58 by apommier #+# #+# */
/* Updated: 2022/04/18 12:50:33 by apommier ### ########.fr */
/* Updated: 2022/04/18 15:48:57 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -237,7 +237,7 @@ void sig_heredoc(int num)
base.sa_handler = &crtl_c;
base.sa_flags = 0;
//close(1);
//printf("sig_heredoc\n");
ft_putchar_fd('\n', 1);
if (sigaction(SIGINT, &base, 0) == -1)
{
printf("sigaction error2\n");
@ -258,8 +258,6 @@ int wait_prompt(t_s_cmd *cmd, int index)
memset(&test, 0, sizeof(test));
test.sa_handler = &sig_heredoc;
test.sa_flags = 0;
in = ft_strjoin(cmd->infile, "\n");
free(cmd->infile);
cmd->infile = 0;
@ -279,15 +277,12 @@ int wait_prompt(t_s_cmd *cmd, int index)
free(input);
ft_putstr_fd("> ", 0);
input = get_next_line(0);
//input = readline("");
//printf("input= -%s-", input);
if (!input)
{
free(in);
free_double(history);
return (0);
return (-1);
}
//input[ft_strlen(input) - 1] = 0;
if (ft_strcmp(input, in))
{
dup = ft_strdup(input);
@ -302,8 +297,6 @@ int wait_prompt(t_s_cmd *cmd, int index)
}
free(in);
free(input);
//free(cmd->infile);
//cmd->infile = 0;//option?
cmd->infile = set_heredoc(index, history);
cmd->in_type = 0;
return (1);
@ -325,10 +318,10 @@ char *set_redirection(t_s_cmd *cmd, char *line, int index)
{
line = ft_input(line, cmd, i);
if (!line)
return (0);
return (error_parsing());
if (cmd->in_type == 1)
{
if (!wait_prompt(cmd, index))
if (wait_prompt(cmd, index) == -1)
{
free(line);
//printf("no waitpromt\n");