mirror of
https://github.com/microsoft/mimalloc.git
synced 2024-12-30 23:43:39 +08:00
emit error message if out-of-memory in C++
This commit is contained in:
parent
d67ff1ca9f
commit
07253fb44c
@ -802,7 +802,10 @@ static bool mi_try_new_handler(bool nothrow) {
|
|||||||
std::set_new_handler(h);
|
std::set_new_handler(h);
|
||||||
#endif
|
#endif
|
||||||
if (h==NULL) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -830,9 +833,9 @@ static std_new_handler_t mi_get_new_handler() {
|
|||||||
static bool mi_try_new_handler(bool nothrow) {
|
static bool mi_try_new_handler(bool nothrow) {
|
||||||
std_new_handler_t h = mi_get_new_handler();
|
std_new_handler_t h = mi_get_new_handler();
|
||||||
if (h==NULL) {
|
if (h==NULL) {
|
||||||
|
_mi_error_message(ENOMEM, "out of memory in 'new'");
|
||||||
if (!nothrow) {
|
if (!nothrow) {
|
||||||
_mi_error_message(EFAULT, "out of memory in 'new' call"); // cannot throw in plain C, use EFAULT to abort
|
abort(); // cannot throw in plain C, use abort
|
||||||
abort();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user