Make LLDB safer to use with respect to the global destructor chain.
authorGreg Clayton <gclayton@apple.com>
Fri, 26 Feb 2016 23:20:08 +0000 (23:20 +0000)
committerGreg Clayton <gclayton@apple.com>
Fri, 26 Feb 2016 23:20:08 +0000 (23:20 +0000)
llvm-svn: 262090

lldb/source/Target/Process.cpp
lldb/source/Target/Target.cpp
lldb/source/Target/Thread.cpp

index 29a16b599bca46d1572f9aed86debb5b91ae9619..8340c4055c189c7e3eacd217d31856a848aa8aad 100644 (file)
@@ -833,13 +833,14 @@ Process::~Process()
 const ProcessPropertiesSP &
 Process::GetGlobalProperties()
 {
-    static ProcessPropertiesSP g_settings_sp;
+    // NOTE: intentional leak so we don't crash if global destructor chain gets
+    // called as other threads still use the result of this function
+    static ProcessPropertiesSP *g_settings_sp_ptr = nullptr;
     static std::once_flag g_once_flag;
     std::call_once(g_once_flag,  []() {
-        if (!g_settings_sp)
-            g_settings_sp.reset (new ProcessProperties (NULL));
+        g_settings_sp_ptr = new ProcessPropertiesSP(new ProcessProperties (NULL));
     });
-    return g_settings_sp;
+    return *g_settings_sp_ptr;
 }
 
 void
index 9719457ff41babcb329ecc4bc22c016045457b18..9ba667690c833193fc8e6ce063f5bc7b9491e337 100644 (file)
@@ -2778,13 +2778,14 @@ Target::RunStopHooks ()
 const TargetPropertiesSP &
 Target::GetGlobalProperties()
 {
-    static TargetPropertiesSP g_settings_sp;
+    // NOTE: intentional leak so we don't crash if global destructor chain gets
+    // called as other threads still use the result of this function
+    static TargetPropertiesSP *g_settings_sp_ptr = nullptr;
     static std::once_flag g_once_flag;
     std::call_once(g_once_flag,  []() {
-        if (!g_settings_sp)
-            g_settings_sp.reset(new TargetProperties(nullptr));
+        g_settings_sp_ptr = new TargetPropertiesSP(new TargetProperties(nullptr));
     });
-    return g_settings_sp;
+    return *g_settings_sp_ptr;
 }
 
 Error
index 5534ab4f349441c07c43b9caba68de70af98cb1a..fd3df8f4eb1783f190eb012ff95f3558be29ed6c 100644 (file)
@@ -59,13 +59,14 @@ using namespace lldb_private;
 const ThreadPropertiesSP &
 Thread::GetGlobalProperties()
 {
-    static ThreadPropertiesSP g_settings_sp;
+    // NOTE: intentional leak so we don't crash if global destructor chain gets
+    // called as other threads still use the result of this function
+    static ThreadPropertiesSP *g_settings_sp_ptr = nullptr;
     static std::once_flag g_once_flag;
     std::call_once(g_once_flag,  []() {
-        if (!g_settings_sp)
-            g_settings_sp.reset (new ThreadProperties (true));
+        g_settings_sp_ptr = new ThreadPropertiesSP(new ThreadProperties (true));
     });
-    return g_settings_sp;
+    return *g_settings_sp_ptr;
 }
 
 static PropertyDefinition