Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Unified Diff: third_party/tcmalloc/chromium/src/debugallocation.cc

Issue 11823061: GTTF: cherry-pick memalign/realloc mismatch debug code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698