Commit 44365ec1fddc12c4e0bdf0cb4b51c1194126ae99

Baptiste 2024-07-23T12:41:25

fixed memleaks using Asan

diff --git a/ekc3/ekc3.c b/ekc3/ekc3.c
index 5e0646f..2fb63a6 100644
--- a/ekc3/ekc3.c
+++ b/ekc3/ekc3.c
@@ -477,6 +477,7 @@ sw ekc3_render_file (const s_str *path)
   file_path_save = *file_path;
   file_path->data.str = *path;
   r = ekc3_render_buf(&in);
+  tag_clean(file_dir);
   *file_dir = file_dir_save;
   *file_path = file_path_save;
   buf_file_close(&in);
diff --git a/ekc3/html.c b/ekc3/html.c
index c244a62..072653c 100644
--- a/ekc3/html.c
+++ b/ekc3/html.c
@@ -34,6 +34,7 @@ s_str * html_escape (const s_str *str, s_str *dest)
     return NULL;
   }
   if (! tag_is_an_associative_list(&escape_tag)) {
+    tag_clean(&escape_tag);
     err_puts("html_escape: EKC3.html_escape is not an associative"
              " List");
     assert(!("html_escape: EKC3.html_escape is not an associative"
@@ -41,8 +42,10 @@ s_str * html_escape (const s_str *str, s_str *dest)
     return NULL;
   }
   escape = escape_tag.data.list;
-  if (! buf_init_alloc(&buf, str->size * 8))
+  if (! buf_init_alloc(&buf, str->size * 8)) {
+    tag_clean(&escape_tag);
     return NULL;
+    }
   tag.type = TAG_STR;
   tag.data.str = (s_str) {0};
   s = *str;
@@ -91,6 +94,7 @@ s_str * html_escape (const s_str *str, s_str *dest)
       }
     }
   }
+  tag_clean(&escape_tag);
   s = (s_str) {0};
   if (! buf_read_to_str(&buf, &s)) {
     buf_clean(&buf);
@@ -100,6 +104,7 @@ s_str * html_escape (const s_str *str, s_str *dest)
   *dest = s;
   return dest;
  ko:
+  tag_clean(&escape_tag);
   buf_clean(&buf);
   return NULL;
 }
diff --git a/libkc3/env.c b/libkc3/env.c
index deb5552..9ea2c35 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -1880,7 +1880,10 @@ s_tag * env_ident_get (s_env *env, const s_ident *ident, s_tag *dest)
     facts_with_cursor_clean(&cursor);
     return NULL;
   }
-  tag_init_copy(&tmp, &tag_var);
+  if (! tag_init_copy(&tmp, &tag_var)) {
+    facts_with_cursor_clean(&cursor);
+    return NULL;
+  }
   facts_with_cursor_clean(&cursor);
   if (! facts_with(&env->facts, &cursor, (t_facts_spec) {
         &tag_ident, &tag_is_a, &tag_macro, NULL, NULL }))