🔨」 fix(builtins/ft_unset): fixed possible leak

This commit is contained in:
y-syo
2024-07-24 19:54:12 +02:00
parent d2943e755d
commit fce47bca2c
2 changed files with 20 additions and 14 deletions

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/25 16:45:04 by mmoussou #+# #+# */ /* Created: 2024/06/25 16:45:04 by mmoussou #+# #+# */
/* Updated: 2024/07/19 11:36:00 by mmoussou ### ########.fr */ /* Updated: 2024/07/24 19:52:10 by mmoussou ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,22 +28,25 @@ void ft_unset_arg(char *arg, t_env *env)
{ {
t_env *tmp; t_env *tmp;
if (!ft_strcmp(env->name, arg)) if (ft_strcmp(arg, "PWD"))
{ {
pop_first_el(env); if (!ft_strcmp(env->name, arg))
return ;
}
while (env->next)
{
if (!ft_strcmp(env->next->name, arg))
{ {
ft_free("cc", &env->next->name, &env->next->content); pop_first_el(env);
tmp = env->next;
env->next = env->next->next;
free(tmp);
return ; return ;
} }
env = env->next; while (env->next)
{
if (!ft_strcmp(env->next->name, arg))
{
ft_free("cc", &env->next->name, &env->next->content);
tmp = env->next;
env->next = env->next->next;
free(tmp);
return ;
}
env = env->next;
}
} }
} }

View File

@ -6,11 +6,12 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/22 14:42:52 by mmoussou #+# #+# */ /* Created: 2024/05/22 14:42:52 by mmoussou #+# #+# */
/* Updated: 2024/07/16 13:19:36 by mmoussou ### ########.fr */ /* Updated: 2024/07/24 19:42:45 by mmoussou ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
#include "builtins.h"
int env_create_first_el(char *env_line, t_env *env) int env_create_first_el(char *env_line, t_env *env)
{ {
@ -71,6 +72,8 @@ t_env *env_init(char **env_d)
} }
ft_envadd_back(&env, new); ft_envadd_back(&env, new);
} }
new = ft_envnew(ft_strdup("PWD"), ft_strdup(ret_cwd()));
ft_envadd_back(&env, new);
return (env); return (env);
} }