[K/N] Better fix for calls checker use-after-free in main thread deinit

This commit is contained in:
Pavel Kunyavskiy
2022-11-15 11:34:00 +01:00
committed by Space Team
parent 3429bccf9a
commit c04e1b6ce7
+6 -6
View File
@@ -113,12 +113,12 @@ extern "C" void DeinitMemory(MemoryState* state, bool destroyRuntime) {
AssertThreadState(state, ThreadState::kNative);
auto* node = mm::FromMemoryState(state);
if (destroyRuntime) {
{
ThreadStateGuard guard(state, ThreadState::kRunnable);
node->Get()->gc().ScheduleAndWaitFullGCWithFinalizers();
// TODO: Why not just destruct `GC` object and its thread data counterpart entirely?
mm::GlobalData::Instance().gc().StopFinalizerThreadIfRunning();
}
ThreadStateGuard guard(state, ThreadState::kRunnable);
node->Get()->gc().ScheduleAndWaitFullGCWithFinalizers();
// TODO: Why not just destruct `GC` object and its thread data counterpart entirely?
mm::GlobalData::Instance().gc().StopFinalizerThreadIfRunning();
}
if (!konan::isOnThreadExitNotSetOrAlreadyStarted()) {
// we can clear reference in advance, as Unregister function can't use it anyway
mm::ThreadRegistry::ClearCurrentThreadData();
}