Cleanup possible WK*Copy/Create leaks in WebKitTestRunner
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Jan 2019 21:04:09 +0000 (21:04 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Jan 2019 21:04:09 +0000 (21:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193340

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2019-01-11
Reviewed by David Kilzer.

* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::didReceiveMessageToPage):
Pull the strings out into a WKRetainPtr.

* WebKitTestRunner/WebNotificationProvider.cpp:
(WTR::WebNotificationProvider::closeWebNotification):
Adopt the created value into the WKRetainPtr.

* WebKitTestRunner/mac/TestControllerMac.mm:
(WTR::generateWhitelist):
Immediately adopt a created value to avoid potential mistakes.

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

Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp
Tools/WebKitTestRunner/WebNotificationProvider.cpp
Tools/WebKitTestRunner/mac/TestControllerMac.mm

index bb5fed7..e4d8319 100644 (file)
@@ -1,3 +1,22 @@
+2019-01-11  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Cleanup possible WK*Copy/Create leaks in WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=193340
+
+        Reviewed by David Kilzer.
+
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::didReceiveMessageToPage):
+        Pull the strings out into a WKRetainPtr.
+
+        * WebKitTestRunner/WebNotificationProvider.cpp:
+        (WTR::WebNotificationProvider::closeWebNotification):
+        Adopt the created value into the WKRetainPtr.
+
+        * WebKitTestRunner/mac/TestControllerMac.mm:
+        (WTR::generateWhitelist):
+        Immediately adopt a created value to avoid potential mistakes.
+
 2019-01-11  Dominik Infuehr  <dinfuehr@igalia.com>
 
         Enable DFG on ARM/Linux again
index 351ee06..e415f90 100644 (file)
@@ -428,11 +428,15 @@ void InjectedBundle::didReceiveMessageToPage(WKBundlePageRef page, WKStringRef m
 
     if (WKStringIsEqualToUTF8CString(messageName, "ResourceLoadStatisticsTelemetryFinished")) {
         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
-        
-        unsigned totalPrevalentResources = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, WKStringCreateWithUTF8CString("TotalPrevalentResources"))));
-        unsigned totalPrevalentResourcesWithUserInteraction = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, WKStringCreateWithUTF8CString("TotalPrevalentResourcesWithUserInteraction"))));
-        unsigned top3SubframeUnderTopFrameOrigins = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, WKStringCreateWithUTF8CString("Top3SubframeUnderTopFrameOrigins"))));
-        
+
+        WKRetainPtr<WKStringRef> totalPrevalentResourcesKey(AdoptWK, WKStringCreateWithUTF8CString("TotalPrevalentResources"));
+        WKRetainPtr<WKStringRef> totalPrevalentResourcesWithUserInteractionKey(AdoptWK, WKStringCreateWithUTF8CString("TotalPrevalentResourcesWithUserInteraction"));
+        WKRetainPtr<WKStringRef> top3SubframeUnderTopFrameOriginsKey(AdoptWK, WKStringCreateWithUTF8CString("Top3SubframeUnderTopFrameOrigins"));
+
+        unsigned totalPrevalentResources = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, totalPrevalentResourcesKey.get())));
+        unsigned totalPrevalentResourcesWithUserInteraction = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, totalPrevalentResourcesWithUserInteractionKey.get())));
+        unsigned top3SubframeUnderTopFrameOrigins = (unsigned)WKUInt64GetValue(static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, top3SubframeUnderTopFrameOriginsKey.get())));
+
         m_testRunner->statisticsDidRunTelemetryCallback(totalPrevalentResources, totalPrevalentResourcesWithUserInteraction, top3SubframeUnderTopFrameOrigins);
         return;
     }
index b009b36..e43f662 100644 (file)
@@ -126,7 +126,7 @@ void WebNotificationProvider::closeWebNotification(WKNotificationRef notificatio
 
     removeGlobalIDFromIDMap(m_localToGlobalNotificationIDMap, id);
 
-    WKRetainPtr<WKUInt64Ref> wkID = WKUInt64Create(id);
+    WKRetainPtr<WKUInt64Ref> wkID(AdoptWK, WKUInt64Create(id));
     WKRetainPtr<WKMutableArrayRef> array(AdoptWK, WKMutableArrayCreate());
     WKArrayAppendItem(array.get(), wkID.get());
     WKNotificationManagerProviderDidCloseNotifications(notificationManager, array.get());
index d575010..583eed4 100644 (file)
@@ -293,22 +293,22 @@ static NSSet *systemHiddenFontFamilySet()
 
 static WKRetainPtr<WKArrayRef> generateWhitelist()
 {
-    WKMutableArrayRef result = WKMutableArrayCreate();
+    WKRetainPtr<WKMutableArrayRef> result = adoptWK(WKMutableArrayCreate());
     for (NSString *fontFamily in allowedFontFamilySet()) {
         NSArray *fontsForFamily = [[NSFontManager sharedFontManager] availableMembersOfFontFamily:fontFamily];
         WKRetainPtr<WKStringRef> familyInFont = adoptWK(WKStringCreateWithUTF8CString([fontFamily UTF8String]));
-        WKArrayAppendItem(result, familyInFont.get());
+        WKArrayAppendItem(result.get(), familyInFont.get());
         for (NSArray *fontInfo in fontsForFamily) {
             // Font name is the first entry in the array.
             WKRetainPtr<WKStringRef> fontName = adoptWK(WKStringCreateWithUTF8CString([[fontInfo objectAtIndex:0] UTF8String]));
-            WKArrayAppendItem(result, fontName.get());
+            WKArrayAppendItem(result.get(), fontName.get());
         }
     }
 
     for (NSString *hiddenFontFamily in systemHiddenFontFamilySet())
-        WKArrayAppendItem(result, adoptWK(WKStringCreateWithUTF8CString([hiddenFontFamily UTF8String])).get());
+        WKArrayAppendItem(result.get(), adoptWK(WKStringCreateWithUTF8CString([hiddenFontFamily UTF8String])).get());
 
-    return adoptWK(result);
+    return result;
 }
 
 void TestController::platformInitializeContext()