Skip to content

Commit 905c179

Browse files
authored
Do not free globals when threads are enabled (#304)
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.
1 parent ba97d55 commit 905c179

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

vm/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,13 @@ int main( int argc, char *argv[] ) {
340340
vm = NULL;
341341
mload = NULL;
342342
neko_vm_select(NULL);
343+
#ifdef NEKO_THREADS
344+
/* With threads enabled, other threads may crash if globals are freed,
345+
so only do a garbage collection there. */
346+
neko_gc_major();
347+
#else
343348
neko_global_free();
349+
#endif
344350
return r;
345351
}
346352

0 commit comments

Comments
 (0)