Title: [239719] trunk
Revision
239719
Author
[email protected]
Date
2019-01-07 18:07:04 -0800 (Mon, 07 Jan 2019)

Log Message

Leak of ScrollCompletionCallbackData (16 bytes) in com.apple.WebKit.WebContent running WebKit layout tests
<https://webkit.org/b/193222>
<rdar://problem/46862309>

Reviewed by Joseph Pecoraro.

Source/WebKit:

* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
(WKBundlePageRegisterScrollOperationCompletionCallback): Change
to return true if callback will be called, else false.
* WebProcess/InjectedBundle/API/c/WKBundlePage.h:
(WKBundlePageRegisterScrollOperationCompletionCallback): Change
to return `bool` value to denote whether callback will be called
(true) or not called (false).

Tools:

* WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
(WTR::executeCallback): Fix camel case of variable name.
(WTR::EventSendingController::callAfterScrollingCompletes): If
WKBundlePageRegisterScrollOperationCompletionCallback() returns
false, make sure to release the ScrollCompletionCallbackData
object.  This fixes the leak.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (239718 => 239719)


--- trunk/Source/WebKit/ChangeLog	2019-01-08 01:37:58 UTC (rev 239718)
+++ trunk/Source/WebKit/ChangeLog	2019-01-08 02:07:04 UTC (rev 239719)
@@ -1,3 +1,19 @@
+2019-01-07  David Kilzer  <[email protected]>
+
+        Leak of ScrollCompletionCallbackData (16 bytes) in com.apple.WebKit.WebContent running WebKit layout tests
+        <https://webkit.org/b/193222>
+        <rdar://problem/46862309>
+
+        Reviewed by Joseph Pecoraro.
+
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
+        (WKBundlePageRegisterScrollOperationCompletionCallback): Change
+        to return true if callback will be called, else false.
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.h:
+        (WKBundlePageRegisterScrollOperationCompletionCallback): Change
+        to return `bool` value to denote whether callback will be called
+        (true) or not called (false).
+
 2019-01-07  Alex Christensen  <[email protected]>
 
         Remove use of NetworkProcess::singleton from CacheStorage::Engine::from

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp (239718 => 239719)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp	2019-01-08 01:37:58 UTC (rev 239718)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp	2019-01-08 02:07:04 UTC (rev 239719)
@@ -632,19 +632,20 @@
     page->ensureTestTrigger();
 }
 
-void WKBundlePageRegisterScrollOperationCompletionCallback(WKBundlePageRef pageRef, WKBundlePageTestNotificationCallback callback, void* context)
+bool WKBundlePageRegisterScrollOperationCompletionCallback(WKBundlePageRef pageRef, WKBundlePageTestNotificationCallback callback, void* context)
 {
     if (!callback)
-        return;
+        return false;
     
     WebKit::WebPage* webPage = WebKit::toImpl(pageRef);
     WebCore::Page* page = webPage ? webPage->corePage() : nullptr;
     if (!page || !page->expectsWheelEventTriggers())
-        return;
+        return false;
     
     page->ensureTestTrigger().setTestCallbackAndStartNotificationTimer([=]() {
         callback(context);
     });
+    return true;
 }
 
 void WKBundlePageCallAfterTasksAndTimers(WKBundlePageRef pageRef, WKBundlePageTestNotificationCallback callback, void* context)

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.h (239718 => 239719)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.h	2019-01-08 01:37:58 UTC (rev 239718)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.h	2019-01-08 02:07:04 UTC (rev 239719)
@@ -120,7 +120,8 @@
 WK_EXPORT WKStringRef WKBundlePageCopyGroupIdentifier(WKBundlePageRef page);
 
 typedef void (*WKBundlePageTestNotificationCallback)(void* context);
-WK_EXPORT void WKBundlePageRegisterScrollOperationCompletionCallback(WKBundlePageRef, WKBundlePageTestNotificationCallback, void* context);
+// Returns true  if the callback function will be called, else false.
+WK_EXPORT bool WKBundlePageRegisterScrollOperationCompletionCallback(WKBundlePageRef, WKBundlePageTestNotificationCallback, void* context);
 
 // Call the given callback after both a postTask() on the page's document's ScriptExecutionContext, and a zero-delay timer.
 WK_EXPORT void WKBundlePageCallAfterTasksAndTimers(WKBundlePageRef, WKBundlePageTestNotificationCallback, void* context);

Modified: trunk/Tools/ChangeLog (239718 => 239719)


--- trunk/Tools/ChangeLog	2019-01-08 01:37:58 UTC (rev 239718)
+++ trunk/Tools/ChangeLog	2019-01-08 02:07:04 UTC (rev 239719)
@@ -1,3 +1,18 @@
+2019-01-07  David Kilzer  <[email protected]>
+
+        Leak of ScrollCompletionCallbackData (16 bytes) in com.apple.WebKit.WebContent running WebKit layout tests
+        <https://webkit.org/b/193222>
+        <rdar://problem/46862309>
+
+        Reviewed by Joseph Pecoraro.
+
+        * WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
+        (WTR::executeCallback): Fix camel case of variable name.
+        (WTR::EventSendingController::callAfterScrollingCompletes): If
+        WKBundlePageRegisterScrollOperationCompletionCallback() returns
+        false, make sure to release the ScrollCompletionCallbackData
+        object.  This fixes the leak.
+
 2019-01-07  Fujii Hironori  <[email protected]>
 
         [Win] EWS: wincairo-ews cannot apply a patch with *.png

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp (239718 => 239719)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp	2019-01-08 01:37:58 UTC (rev 239718)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp	2019-01-08 02:07:04 UTC (rev 239719)
@@ -604,10 +604,10 @@
     if (!context)
         return;
 
-    std::unique_ptr<ScrollCompletionCallbackData> callBackData(reinterpret_cast<ScrollCompletionCallbackData*>(context));
+    std::unique_ptr<ScrollCompletionCallbackData> callbackData(reinterpret_cast<ScrollCompletionCallbackData*>(context));
 
-    JSObjectCallAsFunction(callBackData->m_context, callBackData->m_function, nullptr, 0, nullptr, nullptr);
-    JSValueUnprotect(callBackData->m_context, callBackData->m_function);
+    JSObjectCallAsFunction(callbackData->m_context, callbackData->m_function, nullptr, 0, nullptr, nullptr);
+    JSValueUnprotect(callbackData->m_context, callbackData->m_function);
 }
 
 void EventSendingController::callAfterScrollingCompletes(JSValueRef functionCallback)
@@ -626,8 +626,12 @@
     JSValueProtect(context, functionCallbackObject);
 
     auto scrollCompletionCallbackData = std::make_unique<ScrollCompletionCallbackData>(context, functionCallbackObject);
-
-    WKBundlePageRegisterScrollOperationCompletionCallback(page, executeCallback, scrollCompletionCallbackData.release());
+    auto scrollCompletionCallbackDataPtr = scrollCompletionCallbackData.release();
+    bool callbackWillBeCalled = WKBundlePageRegisterScrollOperationCompletionCallback(page, executeCallback, scrollCompletionCallbackDataPtr);
+    if (!callbackWillBeCalled) {
+        // Reassign raw pointer to std::unique_ptr<> so it will not be leaked.
+        scrollCompletionCallbackData.reset(scrollCompletionCallbackDataPtr);
+    }
 }
 
 #if ENABLE(TOUCH_EVENTS)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to