mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
don't throw std::bad_alloc when out of memory. Instead, terminate immediately
This commit is contained in:
parent
f19afdbfb4
commit
c5f008a416
16
src/init.cpp
16
src/init.cpp
@ -797,6 +797,19 @@ ServiceFlags nLocalServices = NODE_NETWORK;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[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();
|
||||||
|
};
|
||||||
|
|
||||||
bool AppInitBasicSetup()
|
bool AppInitBasicSetup()
|
||||||
{
|
{
|
||||||
// ********************************************************* Step 1: setup
|
// ********************************************************* Step 1: setup
|
||||||
@ -849,6 +862,9 @@ bool AppInitBasicSetup()
|
|||||||
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
|
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::set_new_handler(new_handler_terminate);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user