From: Greg Clayton Date: Fri, 26 Feb 2016 23:20:08 +0000 (+0000) Subject: Make LLDB safer to use with respect to the global destructor chain. X-Git-Tag: llvmorg-3.9.0-rc1~13053 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cc2e27f098b0515a7f4d2478c7bebe30169a49d6;p=platform%2Fupstream%2Fllvm.git Make LLDB safer to use with respect to the global destructor chain. llvm-svn: 262090 --- diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 29a16b599bca..8340c4055c18 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -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 diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 9719457ff41b..9ba667690c83 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -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 diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp index 5534ab4f3494..fd3df8f4eb17 100644 --- a/lldb/source/Target/Thread.cpp +++ b/lldb/source/Target/Thread.cpp @@ -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