diff options
author | Dan Albert <danalbert@google.com> | 2014-05-30 16:00:53 -0700 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2014-06-02 18:48:53 -0700 |
commit | 989725940e765f0065b2bc06b881cde864b62595 (patch) | |
tree | 2fd93597a6381dc47e362c2d2a84faae59bbf2af | |
parent | 3a3b27e04df395b789b92af3d0ed05d2a0f3bf04 (diff) | |
download | bionic-989725940e765f0065b2bc06b881cde864b62595.zip bionic-989725940e765f0065b2bc06b881cde864b62595.tar.gz bionic-989725940e765f0065b2bc06b881cde864b62595.tar.bz2 |
Use __libc_fatal() for failed malloc in new
This way we can print a useful message to the log isntead of just dying
mysteriously.
Change-Id: Ib660c2fd8ce8bb9aa0d0bb634ae08c645d3901e5
-rw-r--r-- | libc/bionic/new.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/libc/bionic/new.cpp b/libc/bionic/new.cpp index cb19dfa..fcfd1bd 100644 --- a/libc/bionic/new.cpp +++ b/libc/bionic/new.cpp @@ -14,15 +14,18 @@ * limitations under the License. */ +#include <errno.h> #include <new> #include <stdlib.h> +#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; } |