⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 281011 in webkit


Ignore:
Timestamp:
Aug 13, 2021, 2:38:55 AM (5 years ago)
Author:
svillar@igalia.com
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.
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r281009 r281011  
     12021-08-13  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        Crash in MockMediaSourcePrivate
     4        https://bugs.webkit.org/show_bug.cgi?id=226795
     5
     6        Reviewed by Darin Adler.
     7
     8        The MockMediaPlayerMediaSource uses callOnMainThread() to execute advanceCurrentTime(). It might
     9        happen that the object is destructed before the callback is executed as it isn't a ref counted
     10        object. That leads to a crash on ASAN builds.
     11
     12        Made the object capable of creating weak ptrs so that we could check whether the _this_ object
     13        has been freed in the meantime or not. For the former case we just bail out.
     14
     15        * platform/mock/mediasource/MockMediaPlayerMediaSource.cpp:
     16        (WebCore::MockMediaPlayerMediaSource::play): Create a WeakPtr.
     17        (WebCore::MockMediaPlayerMediaSource::seekWithTolerance): Ditto.
     18        (WebCore::MockMediaPlayerMediaSource::seekCompleted): Ditto.
     19        * platform/mock/mediasource/MockMediaPlayerMediaSource.h: inherit from CanMakeWeakPtr.
     20
    1212021-08-12  Alex Christensen  <achristensen@webkit.org>
    222
  • trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp

    r278253 r281011  
    124124{
    125125    m_playing = 1;
    126     callOnMainThread([this] {
     126    callOnMainThread([this, weakThis = makeWeakPtr(this)] {
     127        if (!weakThis)
     128            return;
    127129        advanceCurrentTime();
    128130    });
     
    221223
    222224        if (m_playing)
    223             callOnMainThread([this] {
     225            callOnMainThread([this, weakThis = makeWeakPtr(this)] {
     226                if (!weakThis)
     227                    return;
    224228                advanceCurrentTime();
    225229            });
     
    283287
    284288    if (m_playing)
    285         callOnMainThread([this] {
     289        callOnMainThread([this, weakThis = makeWeakPtr(this)] {
     290            if (!weakThis)
     291                return;
    286292            advanceCurrentTime();
    287293        });
  • trunk/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.h

    r278253 r281011  
    3232#include <wtf/Logger.h>
    3333#include <wtf/MediaTime.h>
     34#include <wtf/WeakPtr.h>
    3435
    3536namespace WebCore {
     
    3839class MockMediaSourcePrivate;
    3940
    40 class MockMediaPlayerMediaSource : public MediaPlayerPrivateInterface {
     41class MockMediaPlayerMediaSource : public MediaPlayerPrivateInterface, public CanMakeWeakPtr<MockMediaPlayerMediaSource> {
    4142public:
    4243    explicit MockMediaPlayerMediaSource(MediaPlayer*);
Note: See TracChangeset for help on using the changeset viewer.