Author: Jonas Devlieghere Date: 2026-08-07T05:21:23Z New Revision: 34323ab08e6eed2caff556ecdeae20053cbaaae7
URL: https://github.com/llvm/llvm-project/commit/34323ab08e6eed2caff556ecdeae20053cbaaae7 DIFF: https://github.com/llvm/llvm-project/commit/34323ab08e6eed2caff556ecdeae20053cbaaae7.diff LOG: [lldb] Fix the lazy initialization of Module's global collections (NFC) (#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. Added: Modified: lldb/source/Core/Module.cpp Removed: ################################################################################ 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
