Commit d78da14f38165c4b6aedb26f62acfb687f6f246c

Thomas de Grivel 2024-10-24T12:58:29

fix memleak in map_put

diff --git a/libkc3/map.c b/libkc3/map.c
index 8dc0eda..4dcbdcf 100644
--- a/libkc3/map.c
+++ b/libkc3/map.c
@@ -365,14 +365,15 @@ s_map * map_sort (s_map *map)
 }
 
 s_map * map_put (const s_map *map, const s_tag *key,
-                    const s_tag *value, s_map *dest)
+                 const s_tag *value, s_map *dest)
 {
   s_map tmp = {0};
   uw i = 0;
   map_init_copy(&tmp, map);
   while (i < map->count) {
-    if (compare_tag(key, map->key + i) == 0) {
-      if (! tag_init_copy(map->value + i, value))
+    if (compare_tag(key, tmp.key + i) == 0) {
+      tag_clean(tmp.value + i);
+      if (! tag_init_copy(tmp.value + i, value))
         goto ko;
       *dest = tmp;
       return dest;