Fix DiscardableMemoryPool::free race condition
authorhalcanary <halcanary@google.com>
Thu, 26 Mar 2015 21:08:56 +0000 (14:08 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 26 Mar 2015 21:08:56 +0000 (14:08 -0700)
BUG=skia:3596

Review URL: https://codereview.chromium.org/1017943003

src/lazy/SkDiscardableMemoryPool.cpp

index 1f48366..5b9d87f 100644 (file)
@@ -188,9 +188,9 @@ SkDiscardableMemory* DiscardableMemoryPool::create(size_t bytes) {
 }
 
 void DiscardableMemoryPool::free(PoolDiscardableMemory* dm) {
+    SkAutoMutexAcquire autoMutexAcquire(fMutex);
     // This is called by dm's destructor.
     if (dm->fPointer != NULL) {
-        SkAutoMutexAcquire autoMutexAcquire(fMutex);
         sk_free(dm->fPointer);
         dm->fPointer = NULL;
         SkASSERT(fUsed >= dm->fBytes);