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

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: Created 7 years, 2 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_linux.cc
diff --git a/base/process/memory_linux.cc b/base/process/memory_linux.cc
index f81429b2ac0d7ed72eeeb3d2c4d7882ff6428744..51e53fdfde23131af48d07a26a9a3308da899c92 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, size);
Scott Hess - ex-Googler 2013/10/31 21:54:39 size -> alloc_size.
+ return result;
+}
+
} // namespace base
« 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