Chromium Code Reviews| Index: base/process/memory_linux.cc |
| diff --git a/base/process/memory_linux.cc b/base/process/memory_linux.cc |
| index f81429b2ac0d7ed72eeeb3d2c4d7882ff6428744..2810604fbfc8500d7f48d24b24119de3b622e05e 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" |
| namespace base { |
| @@ -123,6 +124,33 @@ 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 |
| + *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 (alloc_size && (alloc_size / size) != num_items) |
|
willchan no longer on Chromium
2013/11/12 16:04:19
Please add another set of parentheses around the !
kbalazs
2013/11/12 18:40:46
I made a mistake, the first part of the condition
|
| + return NULL; |
|
willchan no longer on Chromium
2013/11/12 16:04:19
Shouldn't this be 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. |
| } |