Attempt to log before terminating if prevector allocation fails

This commit is contained in:
Jack Grigg
2018-04-26 11:30:33 +01:00
parent 3c9dbf3ed8
commit aeb089ecc7
4 changed files with 21 additions and 16 deletions

View File

@@ -723,20 +723,6 @@ 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);
fputs("Error: Out of memory. Terminating.\n", stderr);
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.
*/