Fix ref leak on GrGpu.
Review URL: http://codereview.appspot.com/4323043/
git-svn-id: http://skia.googlecode.com/svn/trunk@1015 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/src/GrBufferAllocPool.cpp b/gpu/src/GrBufferAllocPool.cpp
index 35f0c5e..0db12fe 100644
--- a/gpu/src/GrBufferAllocPool.cpp
+++ b/gpu/src/GrBufferAllocPool.cpp
@@ -34,11 +34,14 @@
size_t blockSize,
int preallocBufferCnt) :
fBlocks(GrMax(8, 2*preallocBufferCnt)) {
+
GrAssert(NULL != gpu);
fGpu = gpu;
+ fGpu->ref();
+ fGpuIsReffed = true;
+
fBufferType = bufferType;
fFrequentResetHint = frequentResetHint;
- fGpu->ref();
fBufferPtr = NULL;
fMinBlockSize = GrMax(GrBufferAllocPool_MIN_BLOCK_SIZE, blockSize);
@@ -61,11 +64,18 @@
buffer->unlock();
}
}
- fPreallocBuffers.unrefAll();
while (!fBlocks.empty()) {
destroyBlock();
}
- fGpu->unref();
+ fPreallocBuffers.unrefAll();
+ releaseGpuRef();
+}
+
+void GrBufferAllocPool::releaseGpuRef() {
+ if (fGpuIsReffed) {
+ fGpu->unref();
+ fGpuIsReffed = false;
+ }
}
void GrBufferAllocPool::reset() {