From 07253fb44c3c220c93dbb64c6dd12c5d7608fb4a Mon Sep 17 00:00:00 2001 From: Daan Date: Sun, 14 Nov 2021 15:33:04 -0800 Subject: [PATCH] emit error message if out-of-memory in C++ --- src/alloc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 1dbd31a7..d9b6dd60 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -802,7 +802,10 @@ static bool mi_try_new_handler(bool nothrow) { std::set_new_handler(h); #endif if (h==NULL) { - if (!nothrow) throw std::bad_alloc(); + _mi_error_message(ENOMEM, "out of memory in 'new'"); + if (!nothrow) { + throw std::bad_alloc(); + } return false; } else { @@ -830,9 +833,9 @@ static std_new_handler_t mi_get_new_handler() { static bool mi_try_new_handler(bool nothrow) { std_new_handler_t h = mi_get_new_handler(); if (h==NULL) { + _mi_error_message(ENOMEM, "out of memory in 'new'"); if (!nothrow) { - _mi_error_message(EFAULT, "out of memory in 'new' call"); // cannot throw in plain C, use EFAULT to abort - abort(); + abort(); // cannot throw in plain C, use abort } return false; }