From acc2f79ed7881178c203b1f7cea31596d42ca6cd Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 30 May 2014 16:00:53 -0700 Subject: [PATCH] Use __libc_fatal() for failed malloc in new This way we can print a useful message to the log isntead of just dying mysteriously. (cherry picked from commit 989725940e765f0065b2bc06b881cde864b62595) Bug: 13564922 Change-Id: I704e1263ec1e7556808348b821a20bacc934eb4a --- libc/bionic/new.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libc/bionic/new.cpp b/libc/bionic/new.cpp index cb19dfae2..fcfd1bdf5 100644 --- a/libc/bionic/new.cpp +++ b/libc/bionic/new.cpp @@ -14,15 +14,18 @@ * limitations under the License. */ +#include #include #include +#include "private/libc_logging.h" + const std::nothrow_t std::nothrow = {}; void* operator new(std::size_t size) { void* p = malloc(size); if (p == NULL) { - abort(); + __libc_fatal("new failed to allocate %zu bytes", size); } return p; } @@ -30,7 +33,7 @@ void* operator new(std::size_t size) { void* operator new[](std::size_t size) { void* p = malloc(size); if (p == NULL) { - abort(); + __libc_fatal("new[] failed to allocate %zu bytes", size); } return p; }