diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-04 20:00:53 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-04 20:00:53 +0000 |
commit | 32799485eb13b8f617bac4b6a3b648d99ff7c196 (patch) | |
tree | 1cefbc94263b3d9a61df1022d07f7079b335e184 /base/process_util_unittest.cc | |
parent | 2beea33feabb7eec84815ecd6fa3c2e2112f1d3e (diff) | |
download | chromium_src-32799485eb13b8f617bac4b6a3b648d99ff7c196.zip chromium_src-32799485eb13b8f617bac4b6a3b648d99ff7c196.tar.gz chromium_src-32799485eb13b8f617bac4b6a3b648d99ff7c196.tar.bz2 |
In CrMallocErrorBreak, do not kill the process if errno is ENOMEM.
This is based on CL 9597031, but clears errno when calling through
the overriden allocators.
BUG=103980
TEST=Covered by ProcessUtilTest.MacTerminateOnHeapCorruption
Review URL: https://chromiumcodereview.appspot.com/9965075
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130712 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_unittest.cc')
-rw-r--r-- | base/process_util_unittest.cc | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index 8d26375f..0b6c135 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -7,6 +7,7 @@ #include <limits> #include "base/command_line.h" +#include "base/debug/alias.h" #include "base/eintr_wrapper.h" #include "base/file_path.h" #include "base/logging.h" @@ -22,12 +23,12 @@ #include "testing/multiprocess_func_list.h" #if defined(OS_LINUX) -#include <errno.h> #include <malloc.h> #include <glib.h> #include <sched.h> #endif #if defined(OS_POSIX) +#include <errno.h> #include <dlfcn.h> #include <fcntl.h> #include <signal.h> @@ -39,6 +40,7 @@ #include <windows.h> #endif #if defined(OS_MACOSX) +#include <mach/vm_param.h> #include <malloc/malloc.h> #include "base/process_util_unittest_mac.h" #endif @@ -448,11 +450,33 @@ TEST_F(ProcessUtilTest, LaunchAsUser) { #if defined(OS_MACOSX) -TEST_F(ProcessUtilTest, MacTerminateOnHeapCorruption) { - // Note that base::EnableTerminationOnHeapCorruption() is called as part of - // test suite setup and does not need to be done again, else mach_override - // will fail. +// For the following Mac tests: +// Note that base::EnableTerminationOnHeapCorruption() is called as part of +// test suite setup and does not need to be done again, else mach_override +// will fail. + +TEST_F(ProcessUtilTest, MacMallocFailureDoesNotTerminate) { + // Install the OOM killer. + base::EnableTerminationOnOutOfMemory(); + + // Test that ENOMEM doesn't crash via CrMallocErrorBreak two ways: the exit + // code and lack of the error string. The number of bytes is one less than + // MALLOC_ABSOLUTE_MAX_SIZE, more than which the system early-returns NULL and + // does not call through malloc_error_break(). See the comment at + // EnableTerminationOnOutOfMemory() for more information. + void* buf = NULL; + ASSERT_EXIT( + buf = malloc(std::numeric_limits<size_t>::max() - (2 * PAGE_SIZE) - 1), + testing::KilledBySignal(SIGTRAP), + "\\*\\*\\* error: can't allocate region.*" + "(Terminating process due to a potential for future heap " + "corruption){0}"); + + base::debug::Alias(buf); +} +TEST_F(ProcessUtilTest, MacTerminateOnHeapCorruption) { + // Assert that freeing an unallocated pointer will crash the process. char buf[3]; #ifndef ADDRESS_SANITIZER ASSERT_DEATH(free(buf), "being freed.*" |