diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-16 17:56:56 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-16 17:56:56 +0000 |
commit | 14055fca73ef88666127f1f9c3b1c62d2ea683f7 (patch) | |
tree | 10ebfa12dea9583eba713bbeefde1ee3a7c99fe4 /third_party | |
parent | 8f097c2739f3ff5099cea0c64a9e18943b16d419 (diff) | |
download | chromium_src-14055fca73ef88666127f1f9c3b1c62d2ea683f7.zip chromium_src-14055fca73ef88666127f1f9c3b1c62d2ea683f7.tar.gz chromium_src-14055fca73ef88666127f1f9c3b1c62d2ea683f7.tar.bz2 |
GTTF: cherry-pick memalign/realloc mismatch debug code
Especially ffmpeg may be prone to errors in this area.
Googlers: see b/1397952 for reference.
BUG=30715
Review URL: https://codereview.chromium.org/11823061
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177171 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/tcmalloc/chromium/src/debugallocation.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/third_party/tcmalloc/chromium/src/debugallocation.cc b/third_party/tcmalloc/chromium/src/debugallocation.cc index 74b8026..cccaf98 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; + } + 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 |