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..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 |