fix leak
This commit is contained in:
parent
c7da1acd4e
commit
ca29e120e5
@ -6,35 +6,12 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/21 18:30:26 by sadjigui #+# #+# */
|
||||
/* Updated: 2022/04/15 02:44:25 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/17 10:05:05 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/minishell.h"
|
||||
|
||||
void ft_ls(char *input)
|
||||
{
|
||||
int i;
|
||||
|
||||
DIR *dir;
|
||||
struct dirent *sd;
|
||||
|
||||
i = ft_strlen("ls");
|
||||
while (input[i] && input[i] != ' ')
|
||||
i++;
|
||||
dir = opendir(".");
|
||||
if (dir == NULL)
|
||||
{
|
||||
printf("stop\n");
|
||||
return ;
|
||||
}
|
||||
while ((sd=readdir(dir)) != NULL)
|
||||
{
|
||||
printf(" >> %s\n", sd->d_name);
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
void del_one(t_s_cmd *cmd)
|
||||
{
|
||||
int i;
|
||||
@ -76,6 +53,7 @@ void add_one(t_s_cmd *cmd)
|
||||
|
||||
i = find_it(cmd->big_cmd->env, "PWD");
|
||||
str = getcwd(p, sizeof(p));
|
||||
free(cmd->big_cmd->env[i]);
|
||||
cmd->big_cmd->env[i] = ft_strjoin("PWD=", p);
|
||||
}
|
||||
|
||||
@ -90,6 +68,7 @@ void change_path(t_s_cmd *cmd)
|
||||
{
|
||||
pwd = find_it(cmd->big_cmd->env, "PWD");
|
||||
old = find_it(cmd->big_cmd->env, "OLDPWD");
|
||||
free(cmd->big_cmd->env[old]);
|
||||
cmd->big_cmd->env[old] = ft_strjoin("OLD", cmd->big_cmd->env[pwd]);
|
||||
// old = 0;
|
||||
// while (tab[old])
|
||||
|
||||
11
srcs/main.c
11
srcs/main.c
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
|
||||
/* Updated: 2022/04/17 02:13:41 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/17 19:26:30 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,7 +26,7 @@ void sig_quit(int num)
|
||||
{
|
||||
num = 0;
|
||||
ft_putstr_fd("\b \b\b \b", 1);
|
||||
//printf("quit num= %d\n", num);
|
||||
printf("quit num= %d\n", num);
|
||||
//exit(0);
|
||||
}
|
||||
|
||||
@ -62,7 +62,10 @@ void print_prompt(char **path)
|
||||
{
|
||||
input = readline("\033[1;31m~$ \033[0m");
|
||||
if (!input)
|
||||
{
|
||||
free_double(path);
|
||||
exit_shell(cmd, 0);
|
||||
}
|
||||
add_history(input);
|
||||
/*if (!ft_strcmp("exit", input) && input)
|
||||
{
|
||||
@ -81,8 +84,8 @@ void print_prompt(char **path)
|
||||
err_var = cmd->err_var;
|
||||
|
||||
path = ft_dup_double(cmd->env);
|
||||
//cmd = 0;
|
||||
free_cmd(cmd);
|
||||
cmd = 0;
|
||||
}
|
||||
else
|
||||
ft_putstr_fd("Minishell: error while parsing command\n", 2);
|
||||
@ -109,7 +112,7 @@ int main(int ac, char **av, char **path)
|
||||
}
|
||||
printf("---MINISHELL START---\n");
|
||||
signal(SIGINT, crtl_c);
|
||||
signal(SIGQUIT, sig_quit);
|
||||
|
||||
print_prompt(env);
|
||||
return (0);
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/09 12:33:30 by apommier #+# #+# */
|
||||
/* Updated: 2022/04/17 02:11:56 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/17 11:05:04 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -19,6 +19,8 @@ void exit_shell(t_cmd *cmd, int ret)
|
||||
i = 0;
|
||||
//if (cmd)
|
||||
// free_double(cmd->env);
|
||||
if (!cmd)
|
||||
exit(ret);
|
||||
if (cmd->tmpin != -1)
|
||||
{
|
||||
dup2(cmd->tmpin, 0);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/09 15:18:58 by apommier #+# #+# */
|
||||
/* Updated: 2022/04/16 11:03:41 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/17 10:25:03 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user