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

Side by Side Diff: base/process/memory.cc

Issue 1039043002: Add base::TerminateBecauseOutOfMemory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Thu Mar 26 23:31:38 PDT 2015 Created 5 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 unified diff | Download patch
« no previous file with comments | « base/process/memory.h ('k') | content/child/child_discardable_shared_memory_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/debug/alias.h"
6 #include "base/logging.h"
5 #include "base/process/memory.h" 7 #include "base/process/memory.h"
6 8
7 namespace base { 9 namespace base {
8 10
11 namespace {
12
13 // Breakpad server already classifies base::`anonymous namespace'::OnNoMemory as
Mark Mentovai 2015/03/27 17:33:35 “already” makes sense for a commit message but has
Vitaly Buka (NO REVIEWS) 2015/03/27 17:36:52 Done.
14 // out-of-memory crash.
15 NOINLINE void OnNoMemory(size_t size) {
16 size_t tmp_size = size;
17 base::debug::Alias(&tmp_size);
18 LOG(FATAL) << "Out of memory. size=" << tmp_size;
19 }
20
21 } // namespace
22
23 void TerminateBecauseOutOfMemory(size_t size) {
24 OnNoMemory(size);
25 }
26
9 // Defined in memory_mac.mm for Mac. 27 // Defined in memory_mac.mm for Mac.
10 #if !defined(OS_MACOSX) 28 #if !defined(OS_MACOSX)
11 29
12 bool UncheckedCalloc(size_t num_items, size_t size, void** result) { 30 bool UncheckedCalloc(size_t num_items, size_t size, void** result) {
13 const size_t alloc_size = num_items * size; 31 const size_t alloc_size = num_items * size;
14 32
15 // Overflow check 33 // Overflow check
16 if (size && ((alloc_size / size) != num_items)) { 34 if (size && ((alloc_size / size) != num_items)) {
17 *result = NULL; 35 *result = NULL;
18 return false; 36 return false;
19 } 37 }
20 38
21 if (!UncheckedMalloc(alloc_size, result)) 39 if (!UncheckedMalloc(alloc_size, result))
22 return false; 40 return false;
23 41
24 memset(*result, 0, alloc_size); 42 memset(*result, 0, alloc_size);
25 return true; 43 return true;
26 } 44 }
27 45
28 #endif 46 #endif
29 47
30 } // namespace base 48 } // namespace base
OLDNEW
« no previous file with comments | « base/process/memory.h ('k') | content/child/child_discardable_shared_memory_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698