Title: [281011] trunk/Source/WebCore
Revision
281011
Author
[email protected]
Date
2021-08-13 02:38:55 -0700 (Fri, 13 Aug 2021)

Log Message

Crash in MockMediaSourcePrivate
https://bugs.webkit.org/show_bug.cgi?id=226795

Reviewed by Darin Adler.

The MockMediaPlayerMediaSource uses callOnMainThread() to execute advanceCurrentTime(). It might
happen that the object is destructed before the callback is executed as it isn't a ref counted
object. That leads to a crash on ASAN builds.

Made the object capable of creating weak ptrs so that we could check whether the _this_ object
has been freed in the meantime or not. For the former case we just bail out.

* platform/mock/mediasource/MockMediaPlayerMediaSource.cpp:
(WebCore::MockMediaPlayerMediaSource::play): Create a WeakPtr.
(WebCore::MockMediaPlayerMediaSource::seekWithTolerance): Ditto.
(WebCore::MockMediaPlayerMediaSource::seekCompleted): Ditto.
* platform/mock/mediasource/MockMediaPlayerMediaSource.h: inherit from CanMakeWeakPtr.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (281010 => 281011)


--- trunk/Source/WebCore/ChangeLog	2021-08-13 08:40:04 UTC (rev 281010)
+++ trunk/Source/WebCore/ChangeLog	2021-08-13 09:38:55 UTC (rev 281011)
@@ -1,3 +1,23 @@
+2021-08-13  Sergio Villar Senin  <[email protected]>
+
+        Crash in MockMediaSourcePrivate
+        https://bugs.webkit.org/show_bug.cgi?id=226795
+
+        Reviewed by Darin Adler.
+
+        The MockMediaPlayerMediaSource uses callOnMainThread() to execute advanceCurrentTime(). It might
+        happen that the object is destructed before the callback is executed as it isn't a ref counted
+        object. That leads to a crash on ASAN builds.
+
+        Made the object capable of creating weak ptrs so that we could check whether the _this_ object
+        has been freed in the meantime or not. For the former case we just bail out.
+
+        * platform/mock/mediasource/MockMediaPlayerMediaSource.cpp:
+        (WebCore::MockMediaPlayerMediaSource::play): Create a WeakPtr.
+        (WebCore::MockMediaPlayerMediaSource::seekWithTolerance): Ditto.
+        (WebCore::MockMediaPlayerMediaSource::seekCompleted): Ditto.
+        * platform/mock/mediasource/MockMediaPlayerMediaSource.h: inherit from CanMakeWeakPtr.
+
 2021-08-12  Alex Christensen  <[email protected]>
 
         Unprefix -webkit-backface-visibility

Modified: trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp (281010 => 281011)


--- trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp	2021-08-13 08:40:04 UTC (rev 281010)
+++ trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp	2021-08-13 09:38:55 UTC (rev 281011)
@@ -123,7 +123,9 @@
 void MockMediaPlayerMediaSource::play()
 {
     m_playing = 1;
-    callOnMainThread([this] {
+    callOnMainThread([this, weakThis = makeWeakPtr(this)] {
+        if (!weakThis)
+            return;
         advanceCurrentTime();
     });
 }
@@ -220,7 +222,9 @@
         m_player->timeChanged();
 
         if (m_playing)
-            callOnMainThread([this] {
+            callOnMainThread([this, weakThis = makeWeakPtr(this)] {
+                if (!weakThis)
+                    return;
                 advanceCurrentTime();
             });
     }
@@ -282,7 +286,9 @@
     m_player->timeChanged();
 
     if (m_playing)
-        callOnMainThread([this] {
+        callOnMainThread([this, weakThis = makeWeakPtr(this)] {
+            if (!weakThis)
+                return;
             advanceCurrentTime();
         });
 }

Modified: trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h (281010 => 281011)


--- trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h	2021-08-13 08:40:04 UTC (rev 281010)
+++ trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h	2021-08-13 09:38:55 UTC (rev 281011)
@@ -31,6 +31,7 @@
 #include "MediaPlayerPrivate.h"
 #include <wtf/Logger.h>
 #include <wtf/MediaTime.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -37,7 +38,7 @@
 class MediaSource;
 class MockMediaSourcePrivate;
 
-class MockMediaPlayerMediaSource : public MediaPlayerPrivateInterface {
+class MockMediaPlayerMediaSource : public MediaPlayerPrivateInterface, public CanMakeWeakPtr<MockMediaPlayerMediaSource> {
 public:
     explicit MockMediaPlayerMediaSource(MediaPlayer*);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to