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

Unified Diff: src/gpu/GrMemoryPool.cpp

Issue 1553233006: Add debug sentinel to GrMemoryPool to check for memory stomping (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 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 | « src/gpu/GrMemoryPool.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrMemoryPool.cpp
diff --git a/src/gpu/GrMemoryPool.cpp b/src/gpu/GrMemoryPool.cpp
index 1e005857b226a6932199695c6e4548ceadf24db9..0fd7e90f6671dca1be2e95f5f28a98be2ffe7a5f 100644
--- a/src/gpu/GrMemoryPool.cpp
+++ b/src/gpu/GrMemoryPool.cpp
@@ -40,8 +40,8 @@ GrMemoryPool::~GrMemoryPool() {
void* GrMemoryPool::allocate(size_t size) {
VALIDATE;
- size = GrSizeAlignUp(size, kAlignment);
size += kPerAllocPad;
+ size = GrSizeAlignUp(size, kAlignment);
if (fTail->fFreeSize < size) {
size_t blockSize = size;
blockSize = SkTMax<size_t>(blockSize, fMinAllocSize);
@@ -59,7 +59,9 @@ void* GrMemoryPool::allocate(size_t size) {
intptr_t ptr = fTail->fCurrPtr;
// We stash a pointer to the block header, just before the allocated space,
// so that we can decrement the live count on delete in constant time.
- *reinterpret_cast<BlockHeader**>(ptr) = fTail;
+ AllocHeader* allocData = reinterpret_cast<AllocHeader*>(ptr);
+ SkDEBUGCODE(allocData->fSentinal = kAssignedMarker);
+ allocData->fHeader = fTail;
ptr += kPerAllocPad;
fTail->fPrevPtr = fTail->fCurrPtr;
fTail->fCurrPtr += size;
@@ -74,7 +76,10 @@ void* GrMemoryPool::allocate(size_t size) {
void GrMemoryPool::release(void* p) {
VALIDATE;
intptr_t ptr = reinterpret_cast<intptr_t>(p) - kPerAllocPad;
- BlockHeader* block = *reinterpret_cast<BlockHeader**>(ptr);
+ AllocHeader* allocData = reinterpret_cast<AllocHeader*>(ptr);
+ SkASSERT(kAssignedMarker == allocData->fSentinal);
+ SkDEBUGCODE(allocData->fSentinal = kFreedMarker);
+ BlockHeader* block = allocData->fHeader;
if (1 == block->fLiveCount) {
// the head block is special, it is reset rather than deleted
if (fHead == block) {
@@ -159,8 +164,12 @@ void GrMemoryPool::validate() {
SkASSERT(ptrOffset == kHeaderSize);
SkASSERT(userStart == block->fCurrPtr);
} else {
- SkASSERT(block == *reinterpret_cast<BlockHeader**>(userStart));
+ AllocHeader* allocData = reinterpret_cast<AllocHeader*>(userStart);
+ SkASSERT(allocData->fSentinal == kAssignedMarker ||
+ allocData->fSentinal == kFreedMarker);
+ SkASSERT(block == allocData->fHeader);
}
+
prev = block;
} while ((block = block->fNext));
SkASSERT(allocCount == fAllocationCnt);
« no previous file with comments | « src/gpu/GrMemoryPool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698