Commit 0df57629227eaa639fc145146acb464d101c19bd

Thomas de Grivel 2025-01-04T20:37:43

fix env_fork race condition

diff --git a/libkc3/kc3.c b/libkc3/kc3.c
index b658c7f..1648076 100644
--- a/libkc3/kc3.c
+++ b/libkc3/kc3.c
@@ -1041,7 +1041,7 @@ u_ptr_w * kc3_thread_new (u_ptr_w *dest, p_callable *start)
     return NULL;
   }
   tag->data.tuple.tag[2].type = TAG_PTR;
-  if (! (tag->data.tuple.tag[2].data.ptr.p = g_kc3_env)) {
+  if (! (tag->data.tuple.tag[2].data.ptr.p = env_fork_new(g_kc3_env))) {
     tag_delete(tag);
     return NULL;
   }
@@ -1061,31 +1061,31 @@ void * kc3_thread_start (void *arg)
   s_callable *start;
   tag = arg;
   if (tag->type != TAG_TUPLE) {
-    err_puts("kc3_thread_start: invalid argument: not a tuple");
+    fprintf(stderr, "kc3_thread_start: invalid argument: not a tuple\n");
     assert(! "kc3_thread_start: invalid argument: not a tuple");
     return NULL;
   }
   if (tag->data.tuple.count != 3) {
-    err_puts("kc3_thread_start: invalid argument:"
-             " tuple arity mismatch");
+    fprintf(stderr, "kc3_thread_start: invalid argument:"
+	    " tuple arity mismatch\n");
     assert(!("kc3_thread_start: invalid argument:"
              " tuple arity mismatch"));
     return NULL;
   }
   if (tag->data.tuple.tag[1].type != TAG_CALLABLE) {
-    err_puts("kc3_thread_start: invalid argument:"
-             " not a Callable (Fn or Cfn)");
+    fprintf(stderr, "kc3_thread_start: invalid argument:"
+	    " not a Callable (Fn or Cfn)\n");
     assert(!("kc3_thread_start: invalid argument:"
              " not a Callable (Fn or Cfn)"));
     return NULL;
   }
   if (tag->data.tuple.tag[2].type != TAG_PTR) {
-    err_puts("kc3_thread_start: invalid argument: not a Ptr");
+    fprintf(stderr, "kc3_thread_start: invalid argument: not a Ptr\n");
     assert(! "kc3_thread_start: invalid argument: not a Ptr");
     return NULL;
   }
   start = tag->data.tuple.tag[1].data.callable;
-  g_kc3_env = env_fork_new((s_env *) tag->data.tuple.tag[2].data.ptr.p);
+  g_kc3_env = tag->data.tuple.tag[2].data.ptr.p;
   if (! eval_callable_call(start, NULL, tag->data.tuple.tag))
     return NULL;
   env_fork_delete(g_kc3_env);