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

Unified Diff: base/process/memory.cc

Issue 55333002: Make possible to check memory allocations inside chromium (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: weak symbol Created 6 years, 10 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
Index: base/process/memory.cc
diff --git a/base/process/memory.cc b/base/process/memory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..01b028997916ad284d3ca0a8b1eef032969149a8
--- /dev/null
+++ b/base/process/memory.cc
@@ -0,0 +1,25 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/process/memory.h"
+
+namespace base {
+
+bool UncheckedCalloc(size_t num_items, size_t size, void** result) {
+ const size_t alloc_size = num_items * size;
+
+ // Overflow check
+ if (size && ((alloc_size / size) != num_items)) {
+ result = NULL;
+ return false;
+ }
+
+ if (!UncheckedMalloc(alloc_size, result))
+ return false;
+
+ memset(result, 0, alloc_size);
+ return true;
+}
+
+}
« no previous file with comments | « base/process/memory.h ('k') | base/process/memory_linux.cc » ('j') | base/process/memory_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698