don't throw std::bad_alloc when out of memory. Instead, terminate immediately
This commit is contained in:
parent
0753a0e8a9
commit
c10b69eb64
15
src/init.cpp
15
src/init.cpp
|
@ -723,6 +723,19 @@ bool AppInitServers(boost::thread_group& threadGroup)
|
|||
return true;
|
||||
}
|
||||
|
||||
[[noreturn]] static void new_handler_terminate()
|
||||
{
|
||||
// Rather than throwing std::bad-alloc if allocation fails, terminate
|
||||
// immediately to (try to) avoid chain corruption.
|
||||
// Since LogPrintf may itself allocate memory, set the handler directly
|
||||
// to terminate first.
|
||||
std::set_new_handler(std::terminate);
|
||||
LogPrintf("Error: Out of memory. Terminating.\n");
|
||||
|
||||
// The log was successful, terminate now.
|
||||
std::terminate();
|
||||
};
|
||||
|
||||
/** Initialize bitcoin.
|
||||
* @pre Parameters should be parsed and config file should be read.
|
||||
*/
|
||||
|
@ -784,6 +797,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||
signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
|
||||
std::set_new_handler(new_handler_terminate);
|
||||
|
||||
// ********************************************************* Step 2: parameter interactions
|
||||
const CChainParams& chainparams = Params();
|
||||
|
||||
|
|
Loading…
Reference in New Issue