Commit 4049a75e894c45884e08d09ab984ded21893ae4d

Thomas de Grivel 2024-08-18T19:13:05

fix double free

diff --git a/.ikc3_history b/.ikc3_history
index 3f44eb5..ea7b717 100644
--- a/.ikc3_history
+++ b/.ikc3_history
@@ -1,5 +1,3 @@
-Sym.type_size(Str)
-Sym.type_size(HTTP.Response)
 Struct.offset(%HTTP.Response{}, :message)
 Sym.type_size(Str)
 Struct.offset(%HTTP.Response{}, :code)
@@ -98,3 +96,4 @@ Facts.with(Facts.env_facts(), [[KC3, :symbol_value, ?]], fn (fact) { puts(fact.o
 Facts.with(Facts.env_facts(), [[?, :symbol_value, ?]], fn (fact) { puts("#{fact.subject} = #{fact.object}"); void })
 Facts.with(Facts.env_facts(), [[?, :symbol_value, ?]], fn (fact) { puts(fact.subject); puts(fact.object); void })
 Facts.with(Facts.env_facts(), [[?, :symbol_value, object = ?], [object, ], fn (fact) { puts(fact.subject); puts(fact.object); void })
+Facts.with(Facts.env_facts(), [[KC3, :operator, ?]], fn (fact) { puts(fact.object); void })
diff --git a/env b/env
index dc185cc..336b40f 100644
--- a/env
+++ b/env
@@ -1,3 +1,4 @@
 export LD_LIBRARY_PATH="$PWD/libkc3/.libs:$PWD/ekc3/.libs:$PWD/http/.libs:$PWD/lib/kc3/0.1:$LD_LIBRARY_PATH"
 export KC3_HTTPD_HOST=0.0.0.0
 export KC3_HTTPD_PORT=58000
+export MALLOC_OPTIONS=CDFGJU
diff --git a/libkc3/env.c b/libkc3/env.c
index 06e8c2c..d4b5a29 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -2078,19 +2078,20 @@ s_tag * env_facts_with_tags (s_env *env, s_facts *facts, s_tag *subject,
       goto ok;
     }
     tag_clean(&tmp);
-    fact_w_init_fact(fact_w, fact);
+    fact_w_clean(fact_w);
+    if (! fact_w_init_fact(fact_w, fact))
+      goto clean;
     if (! env_eval_call_fn_args(env, callback, arguments, &tmp)) {
       fact_w_clean(fact_w);
       goto clean;
     }
-    fact_w_clean(fact_w);
-    fact_w_init(fact_w);
   }
  ok:
-  list_delete_all(arguments);
+  //list_delete_all(arguments);
   *dest = tmp;
   return dest;
  clean:
+  facts_cursor_clean(&cursor);
   tag_clean(&tmp);
   fact_w_clean(fact_w);
   list_delete_all(arguments);
diff --git a/libkc3/struct.c b/libkc3/struct.c
index 559b1ac..0734302 100644
--- a/libkc3/struct.c
+++ b/libkc3/struct.c
@@ -106,9 +106,9 @@ s_struct * struct_allocate (s_struct *s)
   }
   tmp = *s;
   tmp.data = alloc(tmp.type->size);
-  tmp.free_data = true;
   if (! tmp.data)
     return NULL;
+  tmp.free_data = true;
   *s = tmp;
   return s;
 }
diff --git a/libkc3/struct_type.c b/libkc3/struct_type.c
index de59de2..8012a7c 100644
--- a/libkc3/struct_type.c
+++ b/libkc3/struct_type.c
@@ -233,5 +233,5 @@ uw struct_type_padding (uw offset, uw size)
   unsigned int align = 1;
   if (size >= 8)
     align = 8;
-  return (offset + align - 1) / align * align;
+  return (offset + (align - 1)) / align * align;
 }