From 256f845d24792e1551855c46222da48d7697b75c Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sat, 15 Feb 2025 12:11:05 +0000 Subject: [PATCH] Do not free globals when threads are enabled When threads are enabled, it's possible that other threads are still running while neko is shutting down. This means freeing builtins or the thread local storage slot for the vm context may cause a crash on those threads. --- vm/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vm/main.c b/vm/main.c index e003c5ff..2e209168 100644 --- a/vm/main.c +++ b/vm/main.c @@ -340,7 +340,13 @@ int main( int argc, char *argv[] ) { vm = NULL; mload = NULL; neko_vm_select(NULL); + #ifdef NEKO_THREADS + /* With threads enabled, other threads may crash if globals are freed, + so only do a garbage collection there. */ + neko_gc_major(); + #else neko_global_free(); + #endif return r; }