From b85a88853a651a248078194089e9d5563a41350c Mon Sep 17 00:00:00 2001 From: deadbeef Date: Fri, 3 Mar 2017 10:33:18 -0800 Subject: [PATCH] Fixing race between CallbackCanceled and CancelCallback in AsyncInvoker. Pointer was already protected by a critical section in two places but not the third. Added thread annotations to prevent this from happening in the future. BUG=None Review-Url: https://codereview.webrtc.org/2726263004 Cr-Commit-Position: refs/heads/master@{#17017} --- webrtc/base/asyncinvoker-inl.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/webrtc/base/asyncinvoker-inl.h b/webrtc/base/asyncinvoker-inl.h index bce68d94d4..93e7671a95 100644 --- a/webrtc/base/asyncinvoker-inl.h +++ b/webrtc/base/asyncinvoker-inl.h @@ -18,6 +18,7 @@ #include "webrtc/base/messagehandler.h" #include "webrtc/base/sigslot.h" #include "webrtc/base/thread.h" +#include "webrtc/base/thread_annotations.h" namespace rtc { @@ -68,13 +69,16 @@ class NotifyingAsyncClosureBase : public AsyncClosure, CritScope cs(&crit_); callback_ = callback; } - bool CallbackCanceled() const { return calling_thread_ == nullptr; } + bool CallbackCanceled() const { + CritScope cs(&crit_); + return calling_thread_ == nullptr; + } private: Location callback_posted_from_; - Callback0 callback_; CriticalSection crit_; - Thread* calling_thread_; + Callback0 callback_ GUARDED_BY(crit_); + Thread* calling_thread_ GUARDED_BY(crit_); void CancelCallback(); };