Commit 1bb16b066f6bb23685d4096328b71a2f96649c74

Baptiste 2024-07-22T18:27:02

memory leaks corrections

diff --git a/ekc3/ekc3.c b/ekc3/ekc3.c
index ffb9d2e..5e0646f 100644
--- a/ekc3/ekc3.c
+++ b/ekc3/ekc3.c
@@ -249,7 +249,7 @@ sw ekc3_buf_parse_kc3_block (s_buf *buf, s_block *dest)
       goto clean;
     }
     if (! r) {
-      list_delete(*tail);
+      *tail = list_delete(*tail);
       err_puts("ekc3_buf_parse_kc3_block: buf_parse_tag = 0");
       assert(! "ekc3_buf_parse_kc3_block: buf_parse_tag = 0");
       break;
@@ -264,6 +264,7 @@ sw ekc3_buf_parse_kc3_block (s_buf *buf, s_block *dest)
     r = -1;
     goto clean;
   }
+  list_delete_all(list);
   *dest = tmp;
   r = result;
  clean:
diff --git a/ekc3/html.c b/ekc3/html.c
index 41c2138..c244a62 100644
--- a/ekc3/html.c
+++ b/ekc3/html.c
@@ -96,6 +96,7 @@ s_str * html_escape (const s_str *str, s_str *dest)
     buf_clean(&buf);
     return NULL;
   }
+  buf_clean(&buf);
   *dest = s;
   return dest;
  ko:
diff --git a/lib/kc3/0.1/kc3.facts b/lib/kc3/0.1/kc3.facts
index fa30580..e9cd39f 100644
--- a/lib/kc3/0.1/kc3.facts
+++ b/lib/kc3/0.1/kc3.facts
@@ -253,3 +253,5 @@ add {KC3, :symbol, KC3.puts}
 replace {KC3.puts, :symbol_value, cfn Sw "kc3_puts" (Tag)}
 add {KC3, :symbol, KC3.load}
 replace {KC3.load, :symbol_value, cfn Bool "kc3_load" (Str)}
+add {KC3, :symbol, KC3.must_clean}
+replace {KC3.must_clean, :symbol_value, cfn Bool "kc3_must_clean" (Sym, Result)}
diff --git a/libkc3/kc3.c b/libkc3/kc3.c
index ff716c0..22cb80a 100644
--- a/libkc3/kc3.c
+++ b/libkc3/kc3.c
@@ -129,6 +129,12 @@ void kc3_exit (sw code)
   exit((int) code);
 }
 
+bool * kc3_must_clean(const s_sym * const *sym, bool *dest)
+{
+    assert(sym);
+    return sym_must_clean(*sym, dest);
+}
+
 uw * kc3_facts_next_id (uw *dest)
 {
   assert(dest);
diff --git a/libkc3/sym.c b/libkc3/sym.c
index 642e748..e96f927 100644
--- a/libkc3/sym.c
+++ b/libkc3/sym.c
@@ -502,154 +502,154 @@ s_sym_list * sym_list_new (const s_sym *sym, s_sym *free_sym,
   return sym_list;
 }
 
-bool sym_must_clean (const s_sym *sym, bool *must_clean)
+bool * sym_must_clean (const s_sym *sym, bool *must_clean)
 {
   const s_struct_type *st;
   if (sym_is_array_type(sym))
     sym = sym_array_type(sym);
   if (sym == &g_sym_Block) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Bool) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Cfn) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Character) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Complex) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Cow) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_F32) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_F64) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_F128) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Fn) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Integer) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_List) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Map) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Ptr) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_PtrFree) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Ratio) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_S8) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_S16) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_S32) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_S64) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Str) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Struct) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_StructType) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Sym) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Sw) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Tag) {
     *must_clean = true;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_U8) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_U16) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_U32) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_U64) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Uw) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (sym == &g_sym_Var) {
-    *must_clean = false;
-    return true;
+    *must_clean = true;
+    return must_clean;
   }
   if (sym == &g_sym_Void) {
     *must_clean = false;
-    return true;
+    return must_clean;
   }
   if (! struct_type_find(sym, &st))
-    return false;
+    return NULL;
   if (st) {
     *must_clean = st->must_clean;
-    return true;
+    return must_clean;
   }
   err_write_1("sym_must_clean: unknown type: ");
   err_inspect_sym(&sym);
   err_write_1("\n");
   assert(! "sym_must_clean: unknown type");
-  return false;
+  return NULL;
 }
 
 const s_sym * sym_new (const s_str *src)
diff --git a/libkc3/sym.h b/libkc3/sym.h
index c754124..6551936 100644
--- a/libkc3/sym.h
+++ b/libkc3/sym.h
@@ -136,7 +136,7 @@ bool          sym_has_ident_reserved_characters (const s_sym *sym);
 bool          sym_has_reserved_characters (const s_sym *sym);
 bool          sym_is_array_type (const s_sym *sym);
 bool          sym_is_module (const s_sym *sym);
-bool          sym_must_clean (const s_sym *sym, bool *must_clean);
+bool *        sym_must_clean (const s_sym *sym, bool *must_clean);
 bool          sym_search_modules (const s_sym *sym, const s_sym **dest);
 bool          sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,
                                ffi_type **dest);