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;
797
797
798
798
}
799
799
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
+
800
813
bool AppInitBasicSetup ()
801
814
{
802
815
// ********************************************************* Step 1: setup
@@ -849,6 +862,9 @@ bool AppInitBasicSetup()
849
862
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
850
863
signal (SIGPIPE, SIG_IGN);
851
864
#endif
865
+
866
+ std::set_new_handler (new_handler_terminate);
867
+
852
868
return true ;
853
869
}
854
870
You can’t perform that action at this time.
0 commit comments