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
This commit is contained in:
parent
3a3b27e04d
commit
989725940e
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user