contentfiltering tests leak documents
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Feb 2019 22:51:13 +0000 (22:51 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Feb 2019 22:51:13 +0000 (22:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189434
<rdar://44239943>

Reviewed by Simon Fraser.

Changed ContentFilter to capture the blocked Frame as a WeakPtr to break a reference cycle.

This fixes world leaks in several tests in LayoutTests/contentfiltering/.

* bindings/js/ScriptController.h:
* loader/ContentFilter.cpp:
(WebCore::ContentFilter::didDecide):

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/ScriptController.h
Source/WebCore/loader/ContentFilter.cpp

index 9efe061..d6258a3 100644 (file)
@@ -1,3 +1,19 @@
+2019-02-21  Andy Estes  <aestes@apple.com>
+
+        contentfiltering tests leak documents
+        https://bugs.webkit.org/show_bug.cgi?id=189434
+        <rdar://44239943>
+
+        Reviewed by Simon Fraser.
+
+        Changed ContentFilter to capture the blocked Frame as a WeakPtr to break a reference cycle.
+
+        This fixes world leaks in several tests in LayoutTests/contentfiltering/.
+
+        * bindings/js/ScriptController.h:
+        * loader/ContentFilter.cpp:
+        (WebCore::ContentFilter::didDecide):
+
 2019-02-21  Don Olmstead  <don.olmstead@sony.com>
 
         [CMake][Win] Fix !USE(CF) build of WebCore
index 6e9ddca..f7bee05 100644 (file)
@@ -28,6 +28,7 @@
 #include <JavaScriptCore/Strong.h>
 #include <wtf/Forward.h>
 #include <wtf/RefPtr.h>
+#include <wtf/WeakPtr.h>
 #include <wtf/text/TextPosition.h>
 
 #if PLATFORM(COCOA)
@@ -69,7 +70,7 @@ enum ReasonForCallingCanExecuteScripts {
     NotAboutToExecuteScript
 };
 
-class ScriptController {
+class ScriptController : public CanMakeWeakPtr<ScriptController> {
     WTF_MAKE_FAST_ALLOCATED;
 
     using RootObjectMap = HashMap<void*, Ref<JSC::Bindings::RootObject>>;
index 7bc6998..628d51d 100644 (file)
@@ -228,13 +228,12 @@ void ContentFilter::didDecide(State state)
 
     ContentFilterUnblockHandler unblockHandler { m_blockingContentFilter->unblockHandler() };
     unblockHandler.setUnreachableURL(m_documentLoader.documentURL());
-    RefPtr<Frame> frame { m_documentLoader.frame() };
+    auto frame { m_documentLoader.frame() };
     String unblockRequestDeniedScript { m_blockingContentFilter->unblockRequestDeniedScript() };
     if (!unblockRequestDeniedScript.isEmpty() && frame) {
-        static_assert(std::is_base_of<ThreadSafeRefCounted<AbstractFrame>, Frame>::value, "AbstractFrame must be ThreadSafeRefCounted.");
-        unblockHandler.wrapWithDecisionHandler([frame = WTFMove(frame), script = unblockRequestDeniedScript.isolatedCopy()](bool unblocked) {
-            if (!unblocked)
-                frame->script().executeScript(script);
+        unblockHandler.wrapWithDecisionHandler([scriptController = makeWeakPtr(frame->script()), script = unblockRequestDeniedScript.isolatedCopy()](bool unblocked) {
+            if (!unblocked && scriptController)
+                scriptController->executeScript(script);
         });
     }
     m_documentLoader.frameLoader()->client().contentFilterDidBlockLoad(WTFMove(unblockHandler));