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
pull/59/head
Gavin Andresen 12 years ago
parent eef2091fe9
commit d605bc4cd1

@ -1033,6 +1033,9 @@ bool AppInit2(boost::thread_group& threadGroup)
if (!CheckDiskSpace()) if (!CheckDiskSpace())
return false; return false;
if (!strErrors.str().empty())
return InitError(strErrors.str());
RandAddSeedPerfmon(); RandAddSeedPerfmon();
//// debug print //// debug print
@ -1054,9 +1057,6 @@ bool AppInit2(boost::thread_group& threadGroup)
uiInterface.InitMessage(_("Done loading")); uiInterface.InitMessage(_("Done loading"));
if (!strErrors.str().empty())
return InitError(strErrors.str());
// Add wallet transactions that aren't already in a block to mapTransactions // Add wallet transactions that aren't already in a block to mapTransactions
pwalletMain->ReacceptWalletTransactions(); pwalletMain->ReacceptWalletTransactions();

@ -271,6 +271,9 @@ int main(int argc, char *argv[])
} }
else else
{ {
threadGroup.interrupt_all();
threadGroup.join_all();
Shutdown();
return 1; return 1;
} }
} catch (std::exception& e) { } catch (std::exception& e) {

Loading…
Cancel
Save