Fix non thread-safe usage of makeWeakPtr() in MediaPlayerPrivateAVFoundation
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Jul 2019 11:07:41 +0000 (11:07 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Jul 2019 11:07:41 +0000 (11:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199777

Reviewed by Eric Carlson.

The code was calling makeWeakPtr() on a main-thread object, from a background thread.
This is not thread safe. To address the issue, this patches creates the WeakPtr ahead
of time, on the main thread.

* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation):
(WebCore::MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification):
(WebCore::MediaPlayerPrivateAVFoundation::dispatchNotification):
* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@247415 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h

index 15d693c..ea154d6 100644 (file)
@@ -1,3 +1,20 @@
+2019-07-13  Chris Dumez  <cdumez@apple.com>
+
+        Fix non thread-safe usage of makeWeakPtr() in MediaPlayerPrivateAVFoundation
+        https://bugs.webkit.org/show_bug.cgi?id=199777
+
+        Reviewed by Eric Carlson.
+
+        The code was calling makeWeakPtr() on a main-thread object, from a background thread.
+        This is not thread safe. To address the issue, this patches creates the WeakPtr ahead
+        of time, on the main thread.
+
+        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
+        (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation):
+        (WebCore::MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification):
+        (WebCore::MediaPlayerPrivateAVFoundation::dispatchNotification):
+        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:
+
 2019-07-12  Thibault Saunier  <tsaunier@igalia.com>
 
         [GStreamer] Mock GStreamer realtime sources should keep a Ref of their mock realtime media sources
index 2898df8..857f31f 100644 (file)
@@ -55,7 +55,8 @@
 namespace WebCore {
 
 MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation(MediaPlayer* player)
-    : m_player(player)
+    : m_weakThis(makeWeakPtr(*this))
+    , m_player(player)
     , m_queuedNotifications()
     , m_queueMutex()
     , m_networkState(MediaPlayer::Empty)
@@ -774,7 +775,7 @@ void MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification(Notification
     if (delayDispatch && !m_mainThreadCallPending) {
         m_mainThreadCallPending = true;
 
-        callOnMainThread([weakThis = makeWeakPtr(*this)] {
+        callOnMainThread([weakThis = m_weakThis] {
             if (!weakThis)
                 return;
 
@@ -807,7 +808,7 @@ void MediaPlayerPrivateAVFoundation::dispatchNotification()
         }
         
         if (!m_queuedNotifications.isEmpty() && !m_mainThreadCallPending) {
-            callOnMainThread([weakThis = makeWeakPtr(*this)] {
+            callOnMainThread([weakThis = m_weakThis] {
                 if (!weakThis)
                     return;
 
index 51a29bd..a61e5b9 100644 (file)
@@ -327,6 +327,7 @@ protected:
     const URL& resolvedURL() const { return m_resolvedURL; }
 
 private:
+    WeakPtr<MediaPlayerPrivateAVFoundation> m_weakThis;
     MediaPlayer* m_player;
 
     WTF::Function<void()> m_pendingSeek;