From 83e599a7ab49a9ef2e736d3d501b376f7b1993d6 Mon Sep 17 00:00:00 2001 From: herb Date: Thu, 10 Sep 2015 14:16:12 -0700 Subject: [PATCH] Correct a possible free after use. This shows up in TSAN runs as a use-after-free warning. BUG=skia: Review URL: https://codereview.chromium.org/1333003002 --- src/core/SkGlyphCache.cpp | 11 +++-------- src/core/SkGlyphCache_Globals.h | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp index add0ea9f00..6112204869 100644 --- a/src/core/SkGlyphCache.cpp +++ b/src/core/SkGlyphCache.cpp @@ -428,12 +428,10 @@ SkGlyphCache* SkGlyphCache::VisitCache( } cache = new SkGlyphCache(typeface, desc, ctx); - - globals.attachCacheToHead(cache); } - AutoValidate av(cache); AutoAcquire ac(globals.fLock); + globals.internalAttachCacheToHead(cache); cache->fMapMutex.acquireShared(); if (!proc(cache, context)) { // need to reattach @@ -534,9 +532,8 @@ void SkGlyphCache::VisitAll(Visitor visitor, void* context) { /////////////////////////////////////////////////////////////////////////////// -void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) { - AutoAcquire ac(fLock); - +void SkGlyphCache_Globals::internalAttachCacheToHead(SkGlyphCache* cache) { + this->internalPurge(); fCacheCount += 1; cache->fRefCount += 1; // Access to cache->fMemoryUsed is single threaded until internalMoveToHead. @@ -546,8 +543,6 @@ void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) { this->validate(); cache->validate(); - - this->internalPurge(); } SkGlyphCache* SkGlyphCache_Globals::internalGetTail() const { diff --git a/src/core/SkGlyphCache_Globals.h b/src/core/SkGlyphCache_Globals.h index a0069e1433..3736ace414 100644 --- a/src/core/SkGlyphCache_Globals.h +++ b/src/core/SkGlyphCache_Globals.h @@ -74,7 +74,7 @@ public: void purgeAll(); // does not change budget // call when a glyphcache is available for caching (i.e. not in use) - void attachCacheToHead(SkGlyphCache*); + void internalAttachCacheToHead(SkGlyphCache*); // can only be called when the mutex is already held void internalMoveToHead(SkGlyphCache *);