Commit cb1a4ce3aff329100d57ffb5f5f94ce3de5ea054

Thomas de Grivel 2023-12-18T08:55:21

wip asan

diff --git a/libc3/env.c b/libc3/env.c
index 820a251..48fed79 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -110,7 +110,7 @@ bool env_eval_array (s_env *env, const s_array *array, s_array *dest)
   f_init_cast init_cast;
   uw item_size;
   s_tag *tag;
-  s_array tmp;
+  s_array tmp = {0};
   assert(env);
   assert(array);
   assert(dest);
@@ -139,6 +139,7 @@ bool env_eval_array (s_env *env, const s_array *array, s_array *dest)
       goto ko;
     if (! init_cast(data, &tag_eval))
       goto ko;
+    tag_clean(&tag_eval);
     data += item_size;
     tag++;
     i++;
@@ -152,7 +153,7 @@ bool env_eval_array (s_env *env, const s_array *array, s_array *dest)
 
 bool env_eval_array_tag (s_env *env, const s_array *array, s_tag *dest)
 {
-  s_array tmp;
+  s_array tmp = {0};
   if (! env_eval_array(env, array, &tmp))
     return false;
   dest->type = TAG_ARRAY;
diff --git a/libc3/list.c b/libc3/list.c
index 32ab964..62c0285 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -22,20 +22,12 @@
 #include "tag.h"
 #include "tuple.h"
 
-void list_clean (s_list **list)
+void list_clean (s_list *list)
 {
-  s_list *l;
-  s_list *next;
   assert(list);
-  l = *list;
-  while (l) {
-    tag_clean(&l->tag);
-    next = list_next(l);
-    if (l->next.type != TAG_LIST)
-      tag_clean(&l->next);
-    free(l);
-    l = next;
-  }
+  tag_clean(&list->tag);
+  if (list->next.type != TAG_LIST)
+    tag_clean(&list->next);
 }
 
 s_list * list_delete (s_list *list)
@@ -43,10 +35,7 @@ s_list * list_delete (s_list *list)
   s_list *next = NULL;
   if (list) {
     next = list_next(list);
-    tag_clean(&list->tag);
-    next = list_next(list);
-    if (list->next.type != TAG_LIST)
-      tag_clean(&list->next);
+    list_clean(list);
     free(list);
   }
   return next;
@@ -58,6 +47,15 @@ void list_delete_all (s_list *list)
     list = list_delete(list);
 }
 
+void list_f_clean (s_list **list)
+{
+  s_list *l;
+  assert(list);
+  l = *list;
+  while (l)
+    l = list_delete(l);
+}
+
 s_list * list_init (s_list *list, s_list *next)
 {
   assert(list);
diff --git a/libc3/list.h b/libc3/list.h
index 0276b3b..1c6cb5f 100644
--- a/libc3/list.h
+++ b/libc3/list.h
@@ -25,7 +25,7 @@
 #include "list_init.h"
 
 /* Stack-allocation functions, call list_clean after use. */
-void      list_clean (s_list **list);
+void      list_clean (s_list *list);
 s_list  * list_init (s_list *list, s_list *next);
 s_list  * list_init_1 (s_list *list, const s8 *p, s_list *next);
 s_list ** list_init_cast (s_list **list, const s_tag *tag);
@@ -37,6 +37,7 @@ s_list  * list_init_eval (s_list *list, const s8 *p);
 /* Heap-allocation functions, call list_delete after use */
 s_list * list_delete (s_list *list);
 void     list_delete_all (s_list *list);
+void     list_f_clean (s_list **list);
 s_list * list_new (s_list *next);
 s_list * list_new_1 (const s8 *p);
 s_list * list_new_f64 (f64 x, s_list *next);
diff --git a/libc3/sym.c b/libc3/sym.c
index 60329d2..e4ab9ed 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -551,7 +551,7 @@ bool sym_to_clean (const s_sym *type, f_clean *dest)
     return true;
   }
   if (type == sym_1("List")) {
-    *dest = (f_clean) list_clean;
+    *dest = (f_clean) list_f_clean;
     return true;
   }
   if (type == sym_1("Map")) {
diff --git a/libc3/tag_type.c b/libc3/tag_type.c
index c5d8e55..19c08a6 100644
--- a/libc3/tag_type.c
+++ b/libc3/tag_type.c
@@ -272,7 +272,7 @@ bool tag_type_to_clean (e_tag_type type, f_clean *dest)
   case TAG_U32:
   case TAG_U64:
   case TAG_UW:       *dest = NULL;                     return true;
-  case TAG_LIST:     *dest = (f_clean) list_clean;     return true;
+  case TAG_LIST:     *dest = (f_clean) list_f_clean;   return true;
   case TAG_MAP:      *dest = (f_clean) map_clean;      return true;
   case TAG_PTAG:
   case TAG_PTR:      *dest = NULL;                     return true;