DumpRenderTree crashed in com.apple.WebCore: WebCore::MockMediaEndpoint::generateDtls...
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2016 21:45:00 +0000 (21:45 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2016 21:45:00 +0000 (21:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165486
<rdar://problem/29149588>

Reviewed by Tim Horton.

The MockMediaEndpoint can be destroyed before the task created in MockMediaEndpoint::generateDtlsInfo()
gets a chance to run, so guard it with a weak pointer.

* platform/mock/MockMediaEndpoint.cpp:
(WebCore::MockMediaEndpoint::MockMediaEndpoint):
(WebCore::MockMediaEndpoint::generateDtlsInfo):
* platform/mock/MockMediaEndpoint.h:

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

Source/WebCore/ChangeLog
Source/WebCore/platform/mock/MockMediaEndpoint.cpp
Source/WebCore/platform/mock/MockMediaEndpoint.h

index 6673402..e408464 100644 (file)
@@ -1,3 +1,19 @@
+2016-12-06  Sam Weinig  <sam@webkit.org>
+
+        DumpRenderTree crashed in com.apple.WebCore: WebCore::MockMediaEndpoint::generateDtlsInfo const + 23
+        https://bugs.webkit.org/show_bug.cgi?id=165486
+        <rdar://problem/29149588>
+
+        Reviewed by Tim Horton.
+
+        The MockMediaEndpoint can be destroyed before the task created in MockMediaEndpoint::generateDtlsInfo()
+        gets a chance to run, so guard it with a weak pointer.
+
+        * platform/mock/MockMediaEndpoint.cpp:
+        (WebCore::MockMediaEndpoint::MockMediaEndpoint):
+        (WebCore::MockMediaEndpoint::generateDtlsInfo):
+        * platform/mock/MockMediaEndpoint.h:
+
 2016-12-06  Chris Dumez  <cdumez@apple.com>
 
         Add HTML interactive form validation blacklist for some WebKit-specific sites
index 60bb018..253b6e9 100644 (file)
@@ -56,6 +56,7 @@ MockMediaEndpoint::MockMediaEndpoint(MediaEndpointClient& client)
     , m_iceCandidateTimer(*this, &MockMediaEndpoint::iceCandidateTimerFired)
     , m_iceTransportTimer(*this, &MockMediaEndpoint::iceTransportTimerFired)
     , m_unmuteTimer(*this, &MockMediaEndpoint::unmuteTimerFired)
+    , m_weakPtrFactory(this)
 {
 }
 
@@ -71,8 +72,11 @@ std::unique_ptr<RTCDataChannelHandler> MockMediaEndpoint::createDataChannelHandl
 
 void MockMediaEndpoint::generateDtlsInfo()
 {
-    callOnMainThread([this]() {
-        m_client.gotDtlsFingerprint(String(fingerprint), String(fingerprintFunction));
+    auto weakThis = m_weakPtrFactory.createWeakPtr();
+
+    callOnMainThread([weakThis] {
+        if (weakThis)
+            weakThis->m_client.gotDtlsFingerprint(fingerprint, fingerprintFunction);
     });
 }
 
index 13bd47b..7359c8d 100644 (file)
@@ -28,8 +28,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef MockMediaEndpoint_h
-#define MockMediaEndpoint_h
+#pragma once
 
 #if ENABLE(WEB_RTC)
 
@@ -91,10 +90,10 @@ private:
 
     Vector<String> m_midsOfSourcesToUnmute;
     Timer m_unmuteTimer;
+    
+    WeakPtrFactory<MockMediaEndpoint> m_weakPtrFactory;
 };
 
 } // namespace WebCore
 
 #endif // ENABLE(WEB_RTC)
-
-#endif // MockMediaEndpoint_h