From d605bc4cd13716fde9c34d79a01f4ee128f8814f Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Thu, 2 May 2013 12:26:33 -0400 Subject: [PATCH] Exit cleanly if AppInit2 returns false Bitcoin-Qt could core dump if application initialization failed in certain ways. I double-fixed this: 1) qt/bitcoin.cpp now shuts down core threads cleanly if AppInit2 returns false 2) init.cpp now exits before StartNode() if strErrors is set (no reason to StartNode if we're just going to exit immediately anyway). Tested by triggering all of the various ways AppInit2 can fail, either by passing bogus command-line arguments or just recompiling tweaked code to simulate failure. This is a partial fix for #2480 --- src/init.cpp | 6 +++--- src/qt/bitcoin.cpp | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 3845cfad8..c2259f1d7 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1033,6 +1033,9 @@ bool AppInit2(boost::thread_group& threadGroup) if (!CheckDiskSpace()) return false; + if (!strErrors.str().empty()) + return InitError(strErrors.str()); + RandAddSeedPerfmon(); //// debug print @@ -1054,9 +1057,6 @@ bool AppInit2(boost::thread_group& threadGroup) uiInterface.InitMessage(_("Done loading")); - if (!strErrors.str().empty()) - return InitError(strErrors.str()); - // Add wallet transactions that aren't already in a block to mapTransactions pwalletMain->ReacceptWalletTransactions(); diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 25448ea8c..a567eafd5 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -271,6 +271,9 @@ int main(int argc, char *argv[]) } else { + threadGroup.interrupt_all(); + threadGroup.join_all(); + Shutdown(); return 1; } } catch (std::exception& e) {