File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -797,6 +797,19 @@ ServiceFlags nLocalServices = NODE_NETWORK;
797797
798798}
799799
800+ [[noreturn]] static void new_handler_terminate ()
801+ {
802+ // Rather than throwing std::bad-alloc if allocation fails, terminate
803+ // immediately to (try to) avoid chain corruption.
804+ // Since LogPrintf may itself allocate memory, set the handler directly
805+ // to terminate first.
806+ std::set_new_handler (std::terminate);
807+ LogPrintf (" Error: Out of memory. Terminating.\n " );
808+
809+ // The log was successful, terminate now.
810+ std::terminate ();
811+ };
812+
800813bool AppInitBasicSetup ()
801814{
802815 // ********************************************************* Step 1: setup
@@ -849,6 +862,9 @@ bool AppInitBasicSetup()
849862 // Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
850863 signal (SIGPIPE, SIG_IGN);
851864#endif
865+
866+ std::set_new_handler (new_handler_terminate);
867+
852868 return true ;
853869}
854870
You can’t perform that action at this time.
0 commit comments