mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 11:26:51 +01:00
「🔨」 fix(builtins/ft_exit): fixed leaks :D
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/22 13:05:18 by adjoly #+# #+# */
|
/* Created: 2024/06/22 13:05:18 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/07/15 13:29:21 by mmoussou ### ########.fr */
|
/* Updated: 2024/07/15 15:48:38 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -29,7 +29,8 @@ void ft_env(t_env *env);
|
|||||||
|
|
||||||
void ft_unset(char *arg, t_env *env);
|
void ft_unset(char *arg, t_env *env);
|
||||||
|
|
||||||
void ft_exit(char **argv, int ac);
|
void free_exit(t_env *env, char **env_array);
|
||||||
|
void ft_exit(char **argv, int ac, char **env_array, t_env *env);
|
||||||
|
|
||||||
char **env_get_list(t_env *env);
|
char **env_get_list(t_env *env);
|
||||||
void add_to_env(char *name, char *content, t_env *env);
|
void add_to_env(char *name, char *content, t_env *env);
|
||||||
|
@ -3,19 +3,28 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* free_exit.c :+: :+: :+: */
|
/* free_exit.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/15 12:28:36 by adjoly #+# #+# */
|
/* Created: 2024/07/15 12:28:36 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/07/15 15:27:45 by adjoly ### ########.fr */
|
/* Updated: 2024/07/15 15:50:55 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
|
|
||||||
void free_exit(t_env *env)
|
void free_exit(t_env *env, char **env_array)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < 1024)
|
||||||
|
{
|
||||||
|
close(i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
rl_clear_history();
|
rl_clear_history();
|
||||||
ft_envclear(&env, free);
|
ft_envclear(&env, free);
|
||||||
ft_lstclear(get_list(NULL), &free_cmd);
|
ft_lstclear(get_list(NULL), &free_cmd);
|
||||||
|
ft_free("a", &env_array);
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,12 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/14 13:46:57 by adjoly #+# #+# */
|
/* Created: 2024/07/14 13:46:57 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/07/15 15:14:57 by mmoussou ### ########.fr */
|
/* Updated: 2024/07/15 15:49:06 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
#include "builtins.h"
|
||||||
|
|
||||||
int check_exit_value(char *str)
|
int check_exit_value(char *str)
|
||||||
{
|
{
|
||||||
@ -30,7 +31,7 @@ int check_exit_value(char *str)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_exit(char **argv, int ac)
|
void ft_exit(char **argv, int ac, char **env_array, t_env *env)
|
||||||
{
|
{
|
||||||
int return_value;
|
int return_value;
|
||||||
|
|
||||||
@ -39,6 +40,7 @@ void ft_exit(char **argv, int ac)
|
|||||||
if (check_exit_value(argv[1]))
|
if (check_exit_value(argv[1]))
|
||||||
{
|
{
|
||||||
printf("minishell: exit: %s: numeric argument required\n", argv[1]);
|
printf("minishell: exit: %s: numeric argument required\n", argv[1]);
|
||||||
|
free_exit(env, env_array);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -50,6 +52,7 @@ void ft_exit(char **argv, int ac)
|
|||||||
return_value = atoi(argv[1]);
|
return_value = atoi(argv[1]);
|
||||||
if (return_value == -1)
|
if (return_value == -1)
|
||||||
return_value += 255;
|
return_value += 255;
|
||||||
|
free_exit(env, env_array);
|
||||||
exit(get_exit_code(return_value));
|
exit(get_exit_code(return_value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
|
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/07/15 15:23:24 by adjoly ### ########.fr */
|
/* Updated: 2024/07/15 15:47:01 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ void exec_cmd(char *cmd, char **argv, char **env, t_env *env_t)
|
|||||||
if (i == 7)
|
if (i == 7)
|
||||||
ft_env(env_t);
|
ft_env(env_t);
|
||||||
if (i == 1)
|
if (i == 1)
|
||||||
ft_exit(argv, ft_arrlen(argv));
|
ft_exit(argv, ft_arrlen(argv), env, env_t);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
execve(cmd, argv, env);
|
execve(cmd, argv, env);
|
||||||
|
Reference in New Issue
Block a user