Chromium Code Reviews| Index: third_party/tcmalloc/chromium/src/debugallocation.cc |
| diff --git a/third_party/tcmalloc/chromium/src/debugallocation.cc b/third_party/tcmalloc/chromium/src/debugallocation.cc |
| index 74b802609f4639e5a024505a3882f0b94ed8079b..cccaf982b3115451b97e1e9bcbbae4e2c2216e74 100644 |
| --- a/third_party/tcmalloc/chromium/src/debugallocation.cc |
| +++ b/third_party/tcmalloc/chromium/src/debugallocation.cc |
| @@ -743,6 +743,17 @@ class MallocBlock { |
| return FromRawPointer(const_cast<void*>(p)); |
| } |
| + // Return whether p points to memory returned by memalign. |
| + // Requires that p be non-zero and has been checked for sanity with |
| + // FromRawPointer(). |
| + static bool IsMemaligned(const void* p) { |
| + const MallocBlock* mb = reinterpret_cast<const MallocBlock*>( |
| + reinterpret_cast<const char*>(p) - MallocBlock::data_offset()); |
| + // If the offset is non-zero, the block was allocated by memalign |
| + // (see FromRawPointer above). |
| + return mb->offset_ != 0; |
|
jar (doing other things)
2013/01/16 00:59:32
Why is this safe to call if you don't know if this
Paweł Hajdan Jr.
2013/01/16 01:05:09
1. Note this has been reviewed and committed Googl
|
| + } |
| + |
| void Check(int type) const { |
| alloc_map_lock_.Lock(); |
| CheckLocked(type); |
| @@ -1190,13 +1201,18 @@ extern "C" PERFTOOLS_DLL_DECL void* tc_realloc(void* ptr, size_t size) __THROW { |
| MallocHook::InvokeNewHook(ptr, size); |
| return ptr; |
| } |
| + MallocBlock* old = MallocBlock::FromRawPointer(ptr); |
| + old->Check(MallocBlock::kMallocType); |
| + if (MallocBlock::IsMemaligned(ptr)) { |
| + RAW_LOG(FATAL, "realloc/memalign mismatch at %p: " |
| + "non-NULL pointers passed to realloc must be obtained " |
| + "from malloc, calloc, or realloc", ptr); |
| + } |
| if (size == 0) { |
| MallocHook::InvokeDeleteHook(ptr); |
| DebugDeallocate(ptr, MallocBlock::kMallocType); |
| return NULL; |
| } |
| - MallocBlock* old = MallocBlock::FromRawPointer(ptr); |
| - old->Check(MallocBlock::kMallocType); |
| MallocBlock* p = MallocBlock::Allocate(size, MallocBlock::kMallocType); |
| // If realloc fails we are to leave the old block untouched and |