From 1948fef8d540ddaab4682f587b7f636a06f5dc19 Mon Sep 17 00:00:00 2001 From: Carlo Bernaschina Date: Tue, 15 Aug 2017 14:35:16 -0700 Subject: [PATCH] Avoid race condition into NotifyNextFrameOnce (#3980) If GPURasterizer::NotifyNextFrameOnce was rapidly invoked twice could have lead to a null pointer exception. Also ftp::WeakPtr are not thread safe and should not be dereferenced from other threads. --- shell/gpu/gpu_rasterizer.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/shell/gpu/gpu_rasterizer.cc b/shell/gpu/gpu_rasterizer.cc index 8b2b3096f2..edc16d4976 100644 --- a/shell/gpu/gpu_rasterizer.cc +++ b/shell/gpu/gpu_rasterizer.cc @@ -148,14 +148,11 @@ void GPURasterizer::AddNextFrameCallback(ftl::Closure nextFrameCallback) { void GPURasterizer::NotifyNextFrameOnce() { if (nextFrameCallback_) { - blink::Threads::Platform()->PostTask([weak_this = weak_factory_.GetWeakPtr()] { + blink::Threads::Platform()->PostTask([callback = nextFrameCallback_] { TRACE_EVENT0("flutter", "GPURasterizer::NotifyNextFrameOnce"); - if (weak_this) { - ftl::Closure callback = weak_this->nextFrameCallback_; - callback(); - weak_this->nextFrameCallback_ = nullptr; - } + callback(); }); + nextFrameCallback_ = nullptr; } } -- GitLab