1
0
mirror of https://github.com/KeyZox71/ft_minipowershell.git synced 2025-06-25 02:13:35 +02:00

🔨」 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 +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
if (!ft_strcmp(env->name, arg))
if (ft_strcmp(arg, "PWD"))
{
pop_first_el(env);
return ;
}
while (env->next)
{
if (!ft_strcmp(env->next->name, arg))
if (!ft_strcmp(env->name, arg))
{
ft_free("cc", &env->next->name, &env->next->content);
tmp = env->next;
env->next = env->next->next;
free(tmp);
pop_first_el(env);
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;
}
}
}