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

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

Issue 55333002: Make possible to check memory allocations inside chromium (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 1 month 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/process/memory.h" 5 #include "base/process/memory.h"
6 6
7 #include <new> 7 #include <new>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 DVLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str; 173 DVLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str;
174 int score_len = static_cast<int>(score_str.length()); 174 int score_len = static_cast<int>(score_str.length());
175 return (score_len == file_util::WriteFile(oom_file, 175 return (score_len == file_util::WriteFile(oom_file,
176 score_str.c_str(), 176 score_str.c_str(),
177 score_len)); 177 score_len));
178 } 178 }
179 179
180 return false; 180 return false;
181 } 181 }
182 182
183 #if defined(USE_TCMALLOC)
184 void* tc_try_malloc(size_t size) __THROW;
185 #endif
186
187 void* UncheckedMalloc(size_t size) {
188 #if defined(USE_TCMALLOC)
189 return tc_try_malloc(size);
190 #elif defined(LIBC_GLIBC)
191 return __libc_malloc(size);
192 #else
193 #error UncheckedMalloc not implemented on this OS/platform
194 #endif
195 }
196
197 void* UncheckedCalloc(size_t num_items, size_t size) {
198 const size_t alloc_size = num_items * size;
199
200 // Overflow check
201 if (alloc_size && (alloc_size / size) != num_items)
202 return NULL;
203
204 void* result = UncheckedMalloc(alloc_size);
205 if (result)
206 memset(result, 0, size);
Scott Hess - ex-Googler 2013/10/31 21:54:39 size -> alloc_size.
207 return result;
208 }
209
183 } // namespace base 210 } // namespace base
OLDNEW
« base/process/memory.h ('K') | « base/process/memory.h ('k') | base/process/memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698