Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1035)

Unified Diff: base/process_util_unittest.cc

Issue 9597031: In CrMallocErrorBreak, do not kill the process if errno is ENOMEM. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process_util_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process_util_unittest.cc
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc
index d65b5e0e1ba4e4db5ef81b097c12e43bc461c699..771a587633295f1c045f44e2532c4fda3283441b 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
@@ -449,11 +451,27 @@ 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) {
+ // Test that ENOMEM doesn't crash. The number of bytes is one less than
+ // MALLOC_ABSOLUTE_MAX_SIZE, above which the system early-returns NULL and
+ // does not call through malloc_error_break(). See the comment at
+ // EnableTerminationOnOutOfMemory() for more information.
+ void* buf = malloc(std::numeric_limits<size_t>::max() - (2 * PAGE_SIZE) - 1);
+ // The optimizer can be too efficient in Release mode, so alias the value.
+ base::debug::Alias(buf);
+
+ EXPECT_FALSE(buf);
+ EXPECT_EQ(ENOMEM, errno);
+}
+
+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.*"
« no previous file with comments | « base/process_util_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698