Commit 8a2cf6e0df4377a1e1498115acfa876bc2ab1574

Thomas de Grivel 2024-11-04T06:15:59

fix double free in facts_first_with_tags

diff --git a/libkc3/env.c b/libkc3/env.c
index 6fac5e9..d4d06a4 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -2216,8 +2216,6 @@ s_tag * env_facts_first_with (s_env *env, s_facts *facts,
   if (! env_eval_call_fn_args(env, callback, arguments, &tmp)) {
     goto clean;
   }
-  fact_w_clean(fact_w);
-  fact_w_init(fact_w);
  ok:
   list_delete_all(arguments);
   if (true) {
@@ -2230,7 +2228,6 @@ s_tag * env_facts_first_with (s_env *env, s_facts *facts,
  clean:
   facts_with_cursor_clean(&cursor);
   tag_clean(&tmp);
-  fact_w_clean(fact_w);
   list_delete_all(arguments);
   return NULL;  
 }
@@ -2270,7 +2267,6 @@ s_tag * env_facts_first_with_tags (s_env *env, s_facts *facts,
   if (! env_eval_call_fn_args(env, callback, arguments, &tmp)) {
     goto clean;
   }
-  fact_w_clean(fact_w);
  ok:
   list_delete_all(arguments);
   *dest = tmp;
@@ -2278,7 +2274,6 @@ s_tag * env_facts_first_with_tags (s_env *env, s_facts *facts,
  clean:
   facts_cursor_clean(&cursor);
   tag_clean(&tmp);
-  fact_w_clean(fact_w);
   list_delete_all(arguments);
   return NULL;  
 }
diff --git a/libkc3/map.c b/libkc3/map.c
index 6efd622..1a3b732 100644
--- a/libkc3/map.c
+++ b/libkc3/map.c
@@ -34,8 +34,12 @@ s_tag * map_access (const s_map *map, const s_list * const *key,
   assert(dest);
   first = &(*key)->tag;
   next = list_next(*key);
-  if (! next)
-    return map_get(map, first, dest);
+  if (! next) {
+    if (! map_get(map, first, dest)) {
+      tag_init_void(dest);
+      return dest;
+    }
+  }
   if (! map_get(map, first, &tag)) {
     err_write_1("map_access: map_get(");
     err_inspect_map(map);