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

Unified 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: Make possible to check memory allocations inside chromium 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 side-by-side diff with in-line comments
Download patch
Index: base/process/memory_linux.cc
diff --git a/base/process/memory_linux.cc b/base/process/memory_linux.cc
index f81429b2ac0d7ed72eeeb3d2c4d7882ff6428744..305552bc1aaa7868c8ab313af14f0cf912320451 100644
--- a/base/process/memory_linux.cc
+++ b/base/process/memory_linux.cc
@@ -180,4 +180,31 @@ bool AdjustOOMScore(ProcessId process, int score) {
return false;
}
+#if defined(USE_TCMALLOC)
+void* tc_try_malloc(size_t size) __THROW;
+#endif
+
+void* UncheckedMalloc(size_t size) {
+#if defined(USE_TCMALLOC)
+ return tc_try_malloc(size);
+#elif defined(LIBC_GLIBC)
+ return __libc_malloc(size);
+#else
+#error UncheckedMalloc not implemented on this OS/platform
+#endif
+}
+
+void* UncheckedCalloc(size_t num_items, size_t size) {
+ const size_t alloc_size = num_items * size;
+
+ // Overflow check
+ if (alloc_size && (alloc_size / size) != num_items)
+ return NULL;
+
+ void* result = UncheckedMalloc(alloc_size);
+ if (result)
+ memset(result, 0, alloc_size);
+ return result;
+}
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698