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 |