fix leak <<

This commit is contained in:
kinou-p 2022-04-18 14:43:06 +02:00
parent 0f485659bc
commit 6e4c557f3d
3 changed files with 47 additions and 32 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 04:38:12 by apommier ### ########.fr */
/* Updated: 2022/04/18 09:24:25 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -64,25 +64,24 @@ void print_prompt(char **path)
{
char *input;
t_cmd *cmd;
int err_var;
input = 0;
err_var = 0;
cmd = 0;
//int tmpin = dup(0);
//int tmpout = dup(1);
int err_var;
struct sigaction test;
memset(&test, 0, sizeof(test));
test.sa_handler = &sig_quit;
test.sa_flags = 0;
//test.sa_mask = 0;
input = 0;
err_var = 0;
cmd = 0;
if (sigaction(SIGQUIT, &test, 0) == -1)
{
printf("Minishell: sigaction error\n");
exit(1);
}
else
printf("sigaction good\n");
/*else
printf("sigaction good\n");*/
while (1)
{
input = readline("\033[1;31m~$ \033[0m");
@ -92,18 +91,14 @@ void print_prompt(char **path)
exit_shell(cmd, 0);
}
add_history(input);
/*if (!ft_strcmp("exit", input) && input)
{
free(input);
exit_shell(cmd);
}*/
if (ft_strlen(input) && next_space(input, 0) && input)
{
cmd = set_cmd(input, path, err_var);
//path = ft_dup_double(path);
free_double(path);
if (cmd)
{
free_double(path);
//cmd->err_var = 0;
execute(cmd, cmd->env);
err_var = cmd->err_var;
@ -113,7 +108,13 @@ void print_prompt(char **path)
cmd = 0;
}
else
{
/*close(0);
close(1);
dup2(tmpin, 0);
dup2(tmpout, 1);*/
ft_putstr_fd("Minishell: error while parsing command\n", 2);
}
}
free(input);
}
@ -122,17 +123,7 @@ void print_prompt(char **path)
int main(int ac, char **av, char **path)
{
char **env;
//struct sigaction test;
/*test.sa_handler = &sig_quit;
test.sa_flags = 0;
if (sigaction(SIGQUIT, &test, 0) == -1)
{
printf("sigaction error\n");
exit(1);
}
else
printf("sigaction quit good\n");*/
if (!isatty(0))
{
printf("Not today\n");

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */
/* Updated: 2022/04/17 02:08:41 by apommier ### ########.fr */
/* Updated: 2022/04/18 13:22:46 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,7 +33,10 @@ t_s_cmd *set_s_cmd(char *line, int index)
//printf("before redirect\n");
line = set_redirection(s_cmd, line, index);//SET REDIRECTION
if (!line)
{
free(s_cmd);
return (0);
}
split_line = ft_split_with_quote(line, ' ');
//parse_quote(cmd);
//print_double_fd(split_line, 0);
@ -69,6 +72,7 @@ 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);
}
@ -126,8 +130,11 @@ t_cmd *set_cmd(char *input, char **env, int nb)
cmd = split_cmd(cmd, cmds); //split each cmd into args in s_cmd
//printf("end split cdm\n");
if (!cmd)
//free_cmd(cmd);
{
free(cmds);
//printf("no cmd\n");
return (0);
}
parse_quote(cmd);
free(cmds);
if (cmd)

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 15:18:58 by apommier #+# #+# */
/* Updated: 2022/04/17 10:25:03 by apommier ### ########.fr */
/* Updated: 2022/04/18 12:50:33 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -233,9 +233,10 @@ void sig_heredoc(int num)
num = 0;
struct sigaction base;
memset(&base, 0, sizeof(base));
base.sa_handler = &crtl_c;
base.sa_flags = 0;
close(1);
//close(1);
//printf("sig_heredoc\n");
if (sigaction(SIGINT, &base, 0) == -1)
{
@ -251,9 +252,10 @@ int wait_prompt(t_s_cmd *cmd, int index)
char **history;
char *in;
char *dup;
char *del;
struct sigaction test;
memset(&test, 0, sizeof(test));
test.sa_handler = &sig_heredoc;
test.sa_flags = 0;
@ -273,21 +275,32 @@ int wait_prompt(t_s_cmd *cmd, int index)
while (i == 0 || (input && ft_strlen(input) && ft_strcmp(input, in)))
{
i = 1;
if (input)
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);
}
//input[ft_strlen(input) - 1] = 0;
if (ft_strcmp(input, in))
{
dup = ft_strdup(input);
dup[ft_strlen(input) - 1] = 0;
del = dup;
dup = set_var(cmd->big_cmd, dup);
history = add_line(history, dup);
if (dup != del)
free(del);
free(dup);
}
}
free(in);
free(input);
//free(cmd->infile);
//cmd->infile = 0;//option?
@ -316,7 +329,11 @@ char *set_redirection(t_s_cmd *cmd, char *line, int index)
if (cmd->in_type == 1)
{
if (!wait_prompt(cmd, index))
{
free(line);
//printf("no waitpromt\n");
return (0);
}
}
i = 0;
}