Skip to content

Commit 07253fb

Browse files
committed
emit error message if out-of-memory in C++
1 parent d67ff1c commit 07253fb

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/alloc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,10 @@ static bool mi_try_new_handler(bool nothrow) {
802802
std::set_new_handler(h);
803803
#endif
804804
if (h==NULL) {
805-
if (!nothrow) throw std::bad_alloc();
805+
_mi_error_message(ENOMEM, "out of memory in 'new'");
806+
if (!nothrow) {
807+
throw std::bad_alloc();
808+
}
806809
return false;
807810
}
808811
else {
@@ -830,9 +833,9 @@ static std_new_handler_t mi_get_new_handler() {
830833
static bool mi_try_new_handler(bool nothrow) {
831834
std_new_handler_t h = mi_get_new_handler();
832835
if (h==NULL) {
836+
_mi_error_message(ENOMEM, "out of memory in 'new'");
833837
if (!nothrow) {
834-
_mi_error_message(EFAULT, "out of memory in 'new' call"); // cannot throw in plain C, use EFAULT to abort
835-
abort();
838+
abort(); // cannot throw in plain C, use abort
836839
}
837840
return false;
838841
}

0 commit comments

Comments
 (0)