diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2012-10-04 16:35:08 -0400 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2012-10-04 16:35:08 -0400 |
commit | cac6b389d101999d98c3137b17812cce062f924d (patch) | |
tree | fe261633acbb5408d7f7a4e8937fc7c18736ece0 | |
parent | c0b130b79ba720cb6ef4d2c2bb1d422a9386f650 (diff) |
Avoid crashes at shutdown due to printf() in global destructors.
-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 296842acc3..8b08827d73 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -220,8 +220,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); // reopen the log file, if requested if (fReopenDebugLog) { |