diff --git a/src/threads.c b/src/threads.c index e90d3ff..815e623 100644 --- a/src/threads.c +++ b/src/threads.c @@ -29,6 +29,7 @@ void cleanPromise(struct Promise* promise) { promise->refs -= 1; if (promise->refs == 0) { + deleteEnv(promise->env); free(promise); } } @@ -68,6 +69,7 @@ Object async(Object* params, int length, struct Environment* env) .env = env, .object = params[0], // TODO: Clone? }; + env->refs += 1; pthread_create(&promise.promise->thread, NULL, doAsync, promise.promise); return promise;