diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2012-10-04 16:35:08 -0400 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2012-10-09 23:12:50 +0000 |
commit | b3f8f6ab9409d3e901d22c09b0346a5a47779496 (patch) | |
tree | dc2af19f931b953d8c10fe2a409b6a231b4798e1 /src/util.cpp | |
parent | d37a2fd8080cffde4ffbcb9927a66258e9fef39e (diff) | |
download | bitcoin-b3f8f6ab9409d3e901d22c09b0346a5a47779496.tar.xz |
Avoid crashes at shutdown due to printf() in global destructors.
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/util.cpp b/src/util.cpp index 49415fc3b7..62fa4c0575 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -194,8 +194,14 @@ inline int OutputDebugStringF(const char* pszFormat, ...) if (fileout) { static bool fStartedNewLine = true; - static boost::mutex mutexDebugLog; - boost::mutex::scoped_lock scoped_lock(mutexDebugLog); + + // This routine may be called by global destructors during shutdown. + // Since the order of destruction of static/global objects is undefined, + // allocate mutexDebugLog on the heap the first time this routine + // is called to avoid crashes during shutdown. + static boost::mutex* mutexDebugLog = NULL; + if (mutexDebugLog == NULL) mutexDebugLog = new boost::mutex(); + boost::mutex::scoped_lock scoped_lock(*mutexDebugLog); // Debug print useful for profiling if (fLogTimestamps && fStartedNewLine) |