Commit 47ba2113 authored by mbelshe@google.com's avatar mbelshe@google.com

Add a hook for using the std::set_new_handler().

This is what tcmalloc uses to hook out-of-memory cases.

Review URL: http://codereview.chromium.org/99090

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14847 0039d316-1c4b-4281-b951-d872f2087c98
parent e288a8e7
......@@ -109,17 +109,12 @@ void PureCall() {
__debugbreak();
}
int OnNoMemory(size_t memory_size) {
void OnNoMemory() {
// Kill the process. This is important for security, since WebKit doesn't
// NULL-check many memory allocations. If a malloc fails, returns NULL, and
// the buffer is then used, it provides a handy mapping of memory starting at
// address 0 for an attacker to utilize.
__debugbreak();
// Return memory_size so it is not optimized out. Make sure the return value
// is at least 1 so malloc/new is retried, especially useful when under a
// debugger.
return memory_size ? static_cast<int>(memory_size) : 1;
}
// Handlers to silently dump the current process when there is an assert in
......@@ -199,9 +194,7 @@ void RegisterInvalidParamHandler() {
_set_invalid_parameter_handler(InvalidParameter);
_set_purecall_handler(PureCall);
// Gather allocation failure.
_set_new_handler(&OnNoMemory);
// Make sure malloc() calls the new handler too.
_set_new_mode(1);
std::set_new_handler(&OnNoMemory);
#endif
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment