7c72513bfa
This change ensures that operator new will call abort() in case of memory allocation failure. Note that due to our usage of memory overcommit, this can only happen under very rare circumstances (i.e. trying to allocate memory larger than the larger free range of virtual address space, or when memory is corrutped in various ways). Change-Id: I128b8bf626216e899c22a00f24492cd148a1fc94
58 lines
783 B
C++
58 lines
783 B
C++
#include "new"
|
|
#include <stdlib.h>
|
|
|
|
const std::nothrow_t std::nothrow = {};
|
|
|
|
void* operator new(std::size_t size)
|
|
{
|
|
void* p = malloc(size);
|
|
if (p == NULL) {
|
|
abort();
|
|
}
|
|
return p;
|
|
}
|
|
|
|
void* operator new[](std::size_t size)
|
|
{
|
|
void* p = malloc(size);
|
|
if (p == NULL) {
|
|
abort();
|
|
}
|
|
return p;
|
|
}
|
|
|
|
void operator delete(void* ptr)
|
|
{
|
|
free(ptr);
|
|
}
|
|
|
|
void operator delete[](void* ptr)
|
|
{
|
|
free(ptr);
|
|
}
|
|
|
|
void* operator new(std::size_t size, const std::nothrow_t&)
|
|
{
|
|
return malloc(size);
|
|
}
|
|
|
|
void* operator new[](std::size_t size, const std::nothrow_t&)
|
|
{
|
|
return malloc(size);
|
|
}
|
|
|
|
void operator delete(void* ptr, const std::nothrow_t&)
|
|
{
|
|
free(ptr);
|
|
}
|
|
|
|
void operator delete[](void* ptr, const std::nothrow_t&)
|
|
{
|
|
free(ptr);
|
|
}
|
|
|
|
|
|
|
|
|
|
|