From 5ce45fdfb19b6b211e797a804f198bee246a7367 Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Wed, 9 May 2012 18:37:10 +0000 Subject: [PATCH] Remove the string pool from the global destructor chain so it doesn't get yanked out from under us prematurely on exit. rdar://problem/11358062 llvm-svn: 156496 --- lldb/source/Core/ConstString.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lldb/source/Core/ConstString.cpp b/lldb/source/Core/ConstString.cpp index 6a2ac3ffeda8..ea8443467e5b 100644 --- a/lldb/source/Core/ConstString.cpp +++ b/lldb/source/Core/ConstString.cpp @@ -167,12 +167,32 @@ protected: // initializers so we hide the string pool in a static function so // that it will get initialized on the first call to this static // function. +// +// Note, for now we make the string pool a pointer to the pool, because +// we can't guarantee that some objects won't get destroyed after the +// global destructor chain is run, and trying to make sure no destructors +// touch ConstStrings is difficult. So we leak the pool instead. +// +// FIXME: If we are going to keep it this way we should come up with some +// abstraction to "pthread_once" so we don't have to check the pointer +// every time. //---------------------------------------------------------------------- static Pool & StringPool() { - static Pool string_pool; - return string_pool; + static Mutex g_pool_initialization_mutex; + static Pool *g_string_pool = NULL; + + if (g_string_pool == NULL) + { + Mutex::Locker initialization_locker(g_pool_initialization_mutex); + if (g_string_pool == NULL) + { + g_string_pool = new Pool(); + } + } + + return *g_string_pool; } ConstString::ConstString (const char *cstr) :