[Lldb-commits] [lldb] r149131 - in /lldb/trunk: include/lldb/Core/Module.h source/Commands/CommandObjectTarget.cpp source/Core/Module.cpp

Greg Clayton gclayton at apple.com
Fri Jan 27 10:08:35 PST 2012


Author: gclayton
Date: Fri Jan 27 12:08:35 2012
New Revision: 149131

URL: http://llvm.org/viewvc/llvm-project?rev=149131&view=rev
Log:
Fixed an issue that could happen during global object destruction in our
map that tracks all live Module classes. We must leak our mutex for our
collection class as it might be destroyed in an order we can't control.


Modified:
    lldb/trunk/include/lldb/Core/Module.h
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/Module.cpp

Modified: lldb/trunk/include/lldb/Core/Module.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=149131&r1=149130&r2=149131&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Fri Jan 27 12:08:35 2012
@@ -64,7 +64,7 @@
     static Module *
     GetAllocatedModuleAtIndex (size_t idx);
 
-    static Mutex &
+    static Mutex *
     GetAllocationModuleCollectionMutex();
 
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=149131&r1=149130&r2=149131&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Fri Jan 27 12:08:35 2012
@@ -1632,7 +1632,7 @@
     if (check_global_list && num_matches == 0)
     {
         // Check the global list
-        Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex().GetMutex());
+        Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
         const uint32_t num_modules = Module::GetNumberAllocatedModules();
         ModuleSP module_sp;
         for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
@@ -2051,7 +2051,7 @@
                     else
                     {
                         // Check the global list
-                        Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex().GetMutex());
+                        Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
 
                         result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
                     }
@@ -2785,7 +2785,7 @@
             
             if (use_global_module_list)
             {
-                locker.Reset (Module::GetAllocationModuleCollectionMutex().GetMutex());
+                locker.Reset (Module::GetAllocationModuleCollectionMutex()->GetMutex());
                 num_modules = Module::GetNumberAllocatedModules();
             }
             else

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=149131&r1=149130&r2=149131&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Fri Jan 27 12:08:35 2012
@@ -43,11 +43,18 @@
     return *g_module_collection;
 }
 
-Mutex &
+Mutex *
 Module::GetAllocationModuleCollectionMutex()
 {
-    static Mutex g_module_collection_mutex(Mutex::eMutexTypeRecursive);
-    return g_module_collection_mutex;    
+    // NOTE: The mutex below must be leaked since the global module list in
+    // the ModuleList class will get torn at some point, and we can't know
+    // if it will tear itself down before the "g_module_collection_mutex" below
+    // will. So we leak a Mutex object below to safeguard against that
+
+    static Mutex *g_module_collection_mutex = NULL;
+    if (g_module_collection_mutex == NULL)
+        g_module_collection_mutex = new Mutex (Mutex::eMutexTypeRecursive); // NOTE: known leak
+    return g_module_collection_mutex;
 }
 
 size_t





More information about the lldb-commits mailing list