From f9d213650cfe4733937c43d93de91a17f8582820 Mon Sep 17 00:00:00 2001 From: Eladash <18193363+elad335@users.noreply.github.com> Date: Tue, 24 Oct 2023 11:56:09 +0300 Subject: [PATCH] Utilities/Thread.cpp: Fix threads memory leak --- Utilities/Thread.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index c0c3598d29..82a18f4776 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -2223,13 +2223,11 @@ thread_base::native_entry thread_base::finalize(u64 _self) noexcept g_tls_wait_fail = 0; g_tls_access_violation_recovered = false; - const auto fake_self = reinterpret_cast(_self); - g_tls_log_prefix = []() -> std::string { return {}; }; - thread_ctrl::g_tls_this_thread = fake_self; - if (!_self) + if (_self == umax) { + thread_ctrl::g_tls_this_thread = nullptr; return nullptr; } @@ -2463,8 +2461,7 @@ thread_base::~thread_base() // Cleanup abandoned tasks: initialize default results and signal this->exec(); - // Only cleanup on errored status - if ((m_sync & 3) == 2) + // Cleanup { #ifdef _WIN32 const HANDLE handle0 = reinterpret_cast(m_thread.load()); @@ -2650,13 +2647,13 @@ void thread_base::exec() u64 _self = _this->finalize(thread_state::errored); - if (!_self) + if (_self == umax) { // Unused, detached thread support remnant delete _this; } - thread_base::finalize(0); + thread_base::finalize(umax); #ifdef _WIN32 _endthreadex(0);