aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorGavin Andresen <[email protected]>2012-10-09 12:10:18 -0400
committerGavin Andresen <[email protected]>2012-10-09 12:10:18 -0400
commitcf64347d703a53735c9ef1220c93ddfbbaba475c (patch)
tree17dde877bc31a6a21efa47b221a986f4aa31045f /src/util.cpp
parentMerge pull request #1915 from Diapolo/Qt5_compat_leftover (diff)
parentAvoid crashes at shutdown due to printf() in global destructors. (diff)
downloaddiscoin-cf64347d703a53735c9ef1220c93ddfbbaba475c.tar.xz
discoin-cf64347d703a53735c9ef1220c93ddfbbaba475c.zip
Merge branch 'crash_at_exit' of github.com:gavinandresen/bitcoin-git
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 296842acc..8b08827d7 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) {