mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-12 05:00:39 +02:00
Windows: Only deinit the thread CRT when destroying the current thread
The thread termination callback can be called for other threads in the process, not just the current one, in which case we cannot call DeinitCRT. Deinitializing the CRT of another thread would be awkward so just skip that and accept the small leak for now.
This commit is contained in:
1 parent
a6c67ca749
commit
429ff94dc5
2 files changed
+19
-15
No files matched your search
@@ -816,20 +816,22 @@ NTSTATUS ThreadTerm(HANDLE Thread, LONG ExitCode) {
|
||||
auto* OldThreadState = CPUArea.ThreadState();
|
||||
CPUArea.ThreadState() = nullptr;
|
||||
|
||||
{
|
||||
THREAD_BASIC_INFORMATION Info;
|
||||
if (NTSTATUS Err = NtQueryInformationThread(Thread, ThreadBasicInformation, &Info, sizeof(Info), nullptr); Err) {
|
||||
return Err;
|
||||
}
|
||||
THREAD_BASIC_INFORMATION Info;
|
||||
if (NTSTATUS Err = NtQueryInformationThread(Thread, ThreadBasicInformation, &Info, sizeof(Info), nullptr); Err) {
|
||||
return Err;
|
||||
}
|
||||
|
||||
const auto ThreadTID = reinterpret_cast<uint64_t>(Info.ClientId.UniqueThread);
|
||||
const auto ThreadTID = reinterpret_cast<uint64_t>(Info.ClientId.UniqueThread);
|
||||
{
|
||||
std::scoped_lock Lock(ThreadCreationMutex);
|
||||
Threads.erase(ThreadTID);
|
||||
}
|
||||
|
||||
CTX->DestroyThread(OldThreadState);
|
||||
::VirtualFree(reinterpret_cast<void*>(GetCPUArea().EmulatorStackLimit()), 0, MEM_RELEASE);
|
||||
FEX::Windows::DeinitCRTThread();
|
||||
::VirtualFree(reinterpret_cast<void*>(CPUArea.EmulatorStackLimit()), 0, MEM_RELEASE);
|
||||
if (ThreadTID == GetCurrentThreadId()) {
|
||||
FEX::Windows::DeinitCRTThread();
|
||||
}
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user