Improve the failure message upon opt_experimental_infallible_new.

This commit is contained in:
Qi Wang 2022-05-17 13:11:44 -07:00 committed by Qi Wang
parent 70d4102f48
commit cd5aaf308a
2 changed files with 10 additions and 4 deletions

View File

@ -57,8 +57,14 @@ JEMALLOC_NOINLINE
static void * static void *
handleOOM(std::size_t size, bool nothrow) { handleOOM(std::size_t size, bool nothrow) {
if (opt_experimental_infallible_new) { if (opt_experimental_infallible_new) {
safety_check_fail("<jemalloc>: Allocation failed and " const char *huge_warning = (size >= ((std::size_t)1 << 30)) ?
"opt.experimental_infallible_new is true. Aborting.\n"); "This may be caused by heap corruption, if the large size "
"is unexpected (suggest building with sanitizers for "
"debugging)." : "";
safety_check_fail("<jemalloc>: Allocation of size %zu failed. "
"%s opt.experimental_infallible_new is true. Aborting.\n",
size, huge_warning);
return nullptr; return nullptr;
} }

View File

@ -9,8 +9,8 @@
typedef void (*abort_hook_t)(const char *message); typedef void (*abort_hook_t)(const char *message);
bool fake_abort_called; bool fake_abort_called;
void fake_abort(const char *message) { void fake_abort(const char *message) {
if (strcmp(message, "<jemalloc>: Allocation failed and " const char *expected_start = "<jemalloc>: Allocation of size";
"opt.experimental_infallible_new is true. Aborting.\n") != 0) { if (strncmp(message, expected_start, strlen(expected_start) != 0)) {
abort(); abort();
} }
fake_abort_called = true; fake_abort_called = true;