From 132d7d8bc77165444824099beab92dc98ba4d0ab Mon Sep 17 00:00:00 2001 From: Maix0 Date: Mon, 12 Aug 2024 17:15:13 +0200 Subject: [PATCH] Fixed a leak using hmap__remove --- exec/src/builtins/unset.c | 10 ++++++++-- output/src/hashmap/env/env_utils.c | 5 ++--- .../src/hashmap/C__PREFIX___utils.c__TEMPLATE__ | 1 - 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/exec/src/builtins/unset.c b/exec/src/builtins/unset.c index a674cf0e..4945ce41 100644 --- a/exec/src/builtins/unset.c +++ b/exec/src/builtins/unset.c @@ -6,11 +6,12 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/10 18:43:18 by maiboyer #+# #+# */ -/* Updated: 2024/08/11 11:26:16 by maiboyer ### ########.fr */ +/* Updated: 2024/08/12 17:11:12 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "exec/builtins.h" +#include "me/hashmap/hashmap_env.h" #include "me/printf/printf.h" #include "me/str/str.h" #include "me/string/string.h" @@ -18,5 +19,10 @@ t_error builtin_unset_(t_state *state, t_builtin_spawn_info info, t_i32 *exit_code) { - return (*exit_code = 0, ERROR); + t_usize i; + + i = 1; + while (i < info.args.len) + hmap_env_remove(state->env, &info.args.buffer[i++]); + return (*exit_code = 0, NO_ERROR); } diff --git a/output/src/hashmap/env/env_utils.c b/output/src/hashmap/env/env_utils.c index 4e2e99cd..48c5a30c 100644 --- a/output/src/hashmap/env/env_utils.c +++ b/output/src/hashmap/env/env_utils.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* hashmap_env_utils.c :+: :+: :+: */ +/* env_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/06 10:58:20 by maiboyer #+# #+# */ -/* Updated: 2023/12/11 15:35:37 by maiboyer ### ########.fr */ +/* Updated: 2024/08/12 17:14:03 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,7 +39,6 @@ void hmap_env_remove(t_hashmap_env *hmap, t_str *key) hmap->hfunc(&hmap->hasher, key); hashed_key = hasher_reset_and_finish(&hmap->hasher); - hmap->hasher = hasher_sip13_new(); prev = NULL; entry = hmap_env_get_entry(hmap, hashed_key, key, &prev); if (entry == NULL) diff --git a/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ b/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ index 7235ceb0..87cc71a1 100644 --- a/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ +++ b/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ @@ -39,7 +39,6 @@ void hmap_C__PREFIX___remove(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key) hmap->hfunc(&hmap->hasher, key); hashed_key = hasher_reset_and_finish(&hmap->hasher); - hmap->hasher = hasher_sip13_new(); prev = NULL; entry = hmap_C__PREFIX___get_entry(hmap, hashed_key, key, &prev); if (entry == NULL)