Index: base/process/memory_linux.cc |
diff --git a/base/process/memory_linux.cc b/base/process/memory_linux.cc |
index 6bed68bd8320346b1ff98a39417e604e0339b020..bb4c91e0b2dc9a3610b8b4c39ae675e558623057 100644 |
--- a/base/process/memory_linux.cc |
+++ b/base/process/memory_linux.cc |
@@ -11,6 +11,7 @@ |
#include "base/logging.h" |
#include "base/process/internal_linux.h" |
#include "base/strings/string_number_conversions.h" |
+#include "third_party/tcmalloc/chromium/src/gperftools/tcmalloc.h" |
willchan no longer on Chromium
2013/11/28 03:38:28
You should use an #if defined(USE_TCMALLOC) here.
|
namespace base { |
@@ -125,6 +126,35 @@ int posix_memalign(void** ptr, size_t alignment, size_t size) { |
#endif // !*_SANITIZER |
+bool UncheckedMalloc(size_t size, void** result) { |
+#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ |
+ defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER) || \ |
+ (!defined(LIBC_GLIBC) && !defined(USE_TCMALLOC)) |
+ *result = malloc(size); |
+#elif defined(LIBC_GLIBC) && !defined(USE_TCMALLOC) |
+ *result = __libc_malloc(size); |
+#else // tcmalloc |
willchan no longer on Chromium
2013/11/28 03:38:28
please do #elif defined(USE_TCMALLOC) and an #else
|
+ *result = tc_malloc_skip_new_handler(size); |
+#endif |
+ return *result; |
+} |
+ |
+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; |
+} |
+ |
void EnableTerminationOnHeapCorruption() { |
// On Linux, there nothing to do AFAIK. |
} |