Windows: Avoid a double-free if a thread is terminated twice

Unlikely to show up in any real code, but if an attempt is made to terminate
a terminated thread we should handle this gracefully.
This commit is contained in:
Billy Laws committed 2025-08-12 00:51:00 +01:00
1 parent 4df17abea7
commit 8ad1ea499d
2 files changed
+14 -2

No files matched your search

+7 -1
View File
@@ -974,7 +974,13 @@ NTSTATUS ThreadTerm(HANDLE Thread, LONG ExitCode) {
{
std::scoped_lock Lock(ThreadCreationMutex);
Threads.erase(ThreadTID);
auto it = Threads.find(ThreadTID);
if (it == Threads.end()) {
// Thread already terminated
return STATUS_SUCCESS;
}
Threads.erase(it);
if (StatAllocHandler) {
StatAllocHandler->DeallocateSlot(CPUArea.ThreadState()->ThreadStats);
}