Commit 7cff32b6 authored by Hannes Payer's avatar Hannes Payer Committed by Commit Bot

Add a Prefinalizer to CanvasFontCache and move the current destructor content to the Prefinalizer.

This is necessary to resolve a use-after-free issue: the CanvasFontCache is promptly freed on heap tear down but not unregistered from TaskObserver.


Change-Id: I0a048bfd8dcae79d57a882ec553eb4aa9877a77a
Reviewed-on: https://chromium-review.googlesource.com/893140Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532873}
parent 4bf24e83
...@@ -40,10 +40,6 @@ CanvasFontCache::CanvasFontCache(Document& document) ...@@ -40,10 +40,6 @@ CanvasFontCache::CanvasFontCache(Document& document)
} }
CanvasFontCache::~CanvasFontCache() { CanvasFontCache::~CanvasFontCache() {
main_cache_purge_preventer_.reset();
if (pruning_scheduled_) {
Platform::Current()->CurrentThread()->RemoveTaskObserver(this);
}
} }
unsigned CanvasFontCache::MaxFonts() { unsigned CanvasFontCache::MaxFonts() {
...@@ -160,4 +156,11 @@ void CanvasFontCache::Trace(blink::Visitor* visitor) { ...@@ -160,4 +156,11 @@ void CanvasFontCache::Trace(blink::Visitor* visitor) {
visitor->Trace(document_); visitor->Trace(document_);
} }
void CanvasFontCache::Dispose() {
main_cache_purge_preventer_.reset();
if (pruning_scheduled_) {
Platform::Current()->CurrentThread()->RemoveTaskObserver(this);
}
}
} // namespace blink } // namespace blink
...@@ -24,6 +24,8 @@ class FontCachePurgePreventer; ...@@ -24,6 +24,8 @@ class FontCachePurgePreventer;
class CORE_EXPORT CanvasFontCache final class CORE_EXPORT CanvasFontCache final
: public GarbageCollectedFinalized<CanvasFontCache>, : public GarbageCollectedFinalized<CanvasFontCache>,
public WebThread::TaskObserver { public WebThread::TaskObserver {
USING_PRE_FINALIZER(CanvasFontCache, Dispose);
public: public:
static CanvasFontCache* Create(Document& document) { static CanvasFontCache* Create(Document& document) {
return new CanvasFontCache(document); return new CanvasFontCache(document);
...@@ -52,6 +54,7 @@ class CORE_EXPORT CanvasFontCache final ...@@ -52,6 +54,7 @@ class CORE_EXPORT CanvasFontCache final
private: private:
explicit CanvasFontCache(Document&); explicit CanvasFontCache(Document&);
void Dispose();
void SchedulePruningIfNeeded(); void SchedulePruningIfNeeded();
typedef HeapHashMap<String, Member<MutableCSSPropertyValueSet>> typedef HeapHashMap<String, Member<MutableCSSPropertyValueSet>>
MutableStylePropertyMap; MutableStylePropertyMap;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment