[Lldb-commits] [lldb] r143402 - /lldb/trunk/source/Core/Module.cpp

Jim Ingham jingham at apple.com
Mon Oct 31 16:47:10 PDT 2011


Author: jingham
Date: Mon Oct 31 18:47:10 2011
New Revision: 143402

URL: http://llvm.org/viewvc/llvm-project?rev=143402&view=rev
Log:
We can't have the global vector of modules be a static object, or it might get destroyed
before all the modules, which will then crash when the next modules tries to take itself off it.

Modified:
    lldb/trunk/source/Core/Module.cpp

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=143402&r1=143401&r2=143402&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Mon Oct 31 18:47:10 2011
@@ -28,8 +28,17 @@
 static ModuleCollection &
 GetModuleCollection()
 {
-    static ModuleCollection g_module_collection;
-    return g_module_collection;
+    // This module collection needs to live past any module, so we could either make it a
+    // shared pointer in each module or just leak is.  Since it is only an empty vector by
+    // the time all the modules have gone away, we just leak 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 = NULL;
+    if (g_module_collection == NULL)
+        g_module_collection = new ModuleCollection();
+        
+    return *g_module_collection;
 }
 
 Mutex &





More information about the lldb-commits mailing list