https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/214630
Both collections were initialized with a check-then-set on a null pointer, which is race-y. We can achieve the same thing by initializing the pointer with the allocation, while retaining the leak. >From ce9d0df9b97eece30945938cd761fcfc80270143 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere <[email protected]> Date: Thu, 6 Aug 2026 21:07:04 -0700 Subject: [PATCH] [lldb] Fix the lazy initialization of Module's global collections (NFC) Both collections were initialized with a check-then-set on a null pointer, which is race-y. We can achieve the same thing by initializing the pointer with the allocation, while retaining the leak. --- lldb/source/Core/Module.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index da7dec6d97bc2..da3fa21dc225a 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -96,10 +96,7 @@ static ModuleCollection &GetModuleCollection() { // it for now. If we decide this is a big problem we can introduce a // Finalize method that will tear everything down in a predictable order. - static ModuleCollection *g_module_collection = nullptr; - if (g_module_collection == nullptr) - g_module_collection = new ModuleCollection(); - + static ModuleCollection *g_module_collection = new ModuleCollection(); return *g_module_collection; } @@ -109,9 +106,8 @@ std::recursive_mutex &Module::GetAllocationModuleCollectionMutex() { // will tear itself down before the "g_module_collection_mutex" below will. // So we leak a Mutex object below to safeguard against that - static std::recursive_mutex *g_module_collection_mutex = nullptr; - if (g_module_collection_mutex == nullptr) - g_module_collection_mutex = new std::recursive_mutex; // NOTE: known leak + static std::recursive_mutex *g_module_collection_mutex = + new std::recursive_mutex; // NOTE: known leak return *g_module_collection_mutex; } _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
