Commit a5dc42e318a3ede77b0b0797ce5e90a52fad6d35

Thomas de Grivel 2024-12-03T22:15:52

fix memleaks in ikc3 and kc3s

diff --git a/ikc3/ikc3.c b/ikc3/ikc3.c
index fb508d6..3cf2854 100644
--- a/ikc3/ikc3.c
+++ b/ikc3/ikc3.c
@@ -89,12 +89,14 @@ int main (int argc, char **argv)
   s_tag *file_path;
   s_tag  file_path_save;
   FILE *fp = 0;
+  s_buf in_original;
   sw r;
   if (argc < 1)
     return usage("ikc3");
   if (! kc3_init(NULL, &argc, &argv))
     return 1;
   env = g_kc3_env;
+  in_original = *env->in;
   while (argc) {
     if (! strcmp("--load", *argv) ||
         ! strcmp("-l", *argv)) {
@@ -163,6 +165,7 @@ int main (int argc, char **argv)
   buf_linenoise_close(env->in, ".ikc3_history");
 #endif
  clean:
+  *env->in = in_original;
   kc3_clean(NULL);
   return r;
 }
diff --git a/kc3s/kc3s.c b/kc3s/kc3s.c
index e07d7ae..3f1116b 100644
--- a/kc3s/kc3s.c
+++ b/kc3s/kc3s.c
@@ -101,12 +101,14 @@ int main (int argc, char **argv)
   s_tag  file_path_save;
   FILE *fp;
   char  in_data[BUF_SIZE];
+  s_buf in_original;
   sw r;
   if (argc < 1)
     return usage(argv[0]);
   if (! kc3_init(NULL, &argc, &argv))
     return 1;
   env = g_kc3_env;
+  in_original = *env->in;
   buf_init(env->in, false, sizeof(in_data), in_data);
   while (argc) {
     if (! strcmp("--load", *argv) ||
@@ -155,6 +157,7 @@ int main (int argc, char **argv)
   }
   r = kc3s_run();
  clean:
+  *env->in = in_original;
   kc3_clean(NULL);
   return r;
 }