Fix crash in DocumentLoader::startLoadingMainResource
https://bugs.webkit.org/show_bug.cgi?id=185088
rdar://problem/39689263

Reviewed by Chris Dumez.

Add a "protectedThis" to address a case where a deleted "this" was
accessed in a RELEASE_LOG statement.

No new tests -- covered by existing tests, which now pass.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::startLoadingMainResource):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@231128 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 005ee1e..0cd1acf 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,19 @@
+2018-04-27  Keith Rollin  <krollin@apple.com>
+
+        Fix crash in DocumentLoader::startLoadingMainResource
+        https://bugs.webkit.org/show_bug.cgi?id=185088
+        rdar://problem/39689263
+
+        Reviewed by Chris Dumez.
+
+        Add a "protectedThis" to address a case where a deleted "this" was
+        accessed in a RELEASE_LOG statement.
+
+        No new tests -- covered by existing tests, which now pass.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::startLoadingMainResource):
+
 2018-04-27  Simon Fraser  <simon.fraser@apple.com>
 
         Implement color-filter for text stroke
diff --git a/Source/WebCore/loader/DocumentLoader.cpp b/Source/WebCore/loader/DocumentLoader.cpp
index d0f1474..4cc1b18 100644
--- a/Source/WebCore/loader/DocumentLoader.cpp
+++ b/Source/WebCore/loader/DocumentLoader.cpp
@@ -1674,6 +1674,8 @@
     ASSERT(!m_loadingMainResource);
     m_loadingMainResource = true;
 
+    Ref<DocumentLoader> protectedThis(*this);
+
     if (maybeLoadEmpty()) {
         RELEASE_LOG_IF_ALLOWED("startLoadingMainResource: Returning empty document (frame = %p, main = %d)", m_frame, m_frame ? m_frame->isMainFrame() : false);
         return;
@@ -1694,7 +1696,7 @@
     ASSERT(timing().startTime());
     ASSERT(timing().fetchStart());
 
-    willSendRequest(ResourceRequest(m_request), ResourceResponse(), shouldContinue, [this, protectedThis = makeRef(*this)] (ResourceRequest&& request) mutable {
+    willSendRequest(ResourceRequest(m_request), ResourceResponse(), shouldContinue, [this, protectedThis = WTFMove(protectedThis)] (ResourceRequest&& request) mutable {
         m_request = request;
 
         // willSendRequest() may lead to our Frame being detached or cancelling the load via nulling the ResourceRequest.