Title: [218815] trunk/Tools
- Revision
- 218815
- Author
- [email protected]
- Date
- 2017-06-26 11:02:39 -0700 (Mon, 26 Jun 2017)
Log Message
[TestWebKitAPI] Fix false-positive bad release warnings found by clang static analyzer
<https://webkit.org/b/173837>
Reviewed by Geoffrey Garen.
The clang static analyzer can't reason about objects that are
assigned to a delegate as +1 retained, and then released
later in a different method when the delegate is cleared.
Instead, use a common idiom where the object setting the
delegate retains it as an instance variable on initialization.
Then the same object clears the delegate and releases its
instance variable during teardown.
Also add EXPECT_TRUE() tests to make sure the delegate objects
match before teardown.
* TestWebKitAPI/Tests/mac/FullscreenZoomInitialFrame.mm:
(TestWebKitAPI::FullscreenZoomInitialFrame::initializeView):
(TestWebKitAPI::FullscreenZoomInitialFrame::teardownView):
* TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm:
(TestWebKitAPI::PageVisibilityStateWithWindowChanges::initializeView):
(TestWebKitAPI::PageVisibilityStateWithWindowChanges::teardownView):
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (218814 => 218815)
--- trunk/Tools/ChangeLog 2017-06-26 18:01:22 UTC (rev 218814)
+++ trunk/Tools/ChangeLog 2017-06-26 18:02:39 UTC (rev 218815)
@@ -1,5 +1,31 @@
2017-06-26 David Kilzer <[email protected]>
+ [TestWebKitAPI] Fix false-positive bad release warnings found by clang static analyzer
+ <https://webkit.org/b/173837>
+
+ Reviewed by Geoffrey Garen.
+
+ The clang static analyzer can't reason about objects that are
+ assigned to a delegate as +1 retained, and then released
+ later in a different method when the delegate is cleared.
+
+ Instead, use a common idiom where the object setting the
+ delegate retains it as an instance variable on initialization.
+ Then the same object clears the delegate and releases its
+ instance variable during teardown.
+
+ Also add EXPECT_TRUE() tests to make sure the delegate objects
+ match before teardown.
+
+ * TestWebKitAPI/Tests/mac/FullscreenZoomInitialFrame.mm:
+ (TestWebKitAPI::FullscreenZoomInitialFrame::initializeView):
+ (TestWebKitAPI::FullscreenZoomInitialFrame::teardownView):
+ * TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm:
+ (TestWebKitAPI::PageVisibilityStateWithWindowChanges::initializeView):
+ (TestWebKitAPI::PageVisibilityStateWithWindowChanges::teardownView):
+
+2017-06-26 David Kilzer <[email protected]>
+
[TestWebKitAPI] REGRESSION (r218750): Fix leak of NSURLResponse in WKURLSchemeHandler-1.mm
<https://webkit.org/b/173836>
Modified: trunk/Tools/TestWebKitAPI/Tests/mac/FullscreenZoomInitialFrame.mm (218814 => 218815)
--- trunk/Tools/TestWebKitAPI/Tests/mac/FullscreenZoomInitialFrame.mm 2017-06-26 18:01:22 UTC (rev 218814)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/FullscreenZoomInitialFrame.mm 2017-06-26 18:02:39 UTC (rev 218815)
@@ -88,12 +88,15 @@
void setPageScale(WKView *, double);
void sendMouseDownEvent(WebView *, NSEvent *);
void sendMouseDownEvent(WKView *, NSEvent *);
+
+private:
+ RetainPtr<id <WebUIDelegate>> m_delegate;
};
void FullscreenZoomInitialFrame::initializeView(WebView *webView)
{
- // Released in teardownView.
- webView.UIDelegate = [[FullscreenStateDelegate alloc] init];
+ m_delegate = adoptNS([[FullscreenStateDelegate alloc] init]);
+ webView.UIDelegate = m_delegate.get();
RetainPtr<WebPreferences> customPreferences = adoptNS([[WebPreferences alloc] initWithIdentifier:@"FullscreenZoomInitialFramePreferences"]);
[customPreferences setFullScreenEnabled:YES];
@@ -102,9 +105,9 @@
void FullscreenZoomInitialFrame::teardownView(WebView *webView)
{
- id uiDelegate = webView.UIDelegate;
+ EXPECT_TRUE(webView.UIDelegate == m_delegate.get());
webView.UIDelegate = nil;
- [uiDelegate release];
+ m_delegate = nil;
}
void FullscreenZoomInitialFrame::initializeView(WKView *wkView)
Modified: trunk/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm (218814 => 218815)
--- trunk/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm 2017-06-26 18:01:22 UTC (rev 218814)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm 2017-06-26 18:02:39 UTC (rev 218815)
@@ -77,20 +77,24 @@
void initializeView(WKView *) override;
void teardownView(WebView *) override;
void teardownView(WKView *) override;
+
+private:
+ RetainPtr<id <WebUIDelegate>> m_delegate;
};
void PageVisibilityStateWithWindowChanges::initializeView(WebView *webView)
{
- // Released in teardownView.
- webView.UIDelegate = [[PageVisibilityStateDelegate alloc] init];
+ m_delegate = adoptNS([[PageVisibilityStateDelegate alloc] init]);
+ webView.UIDelegate = m_delegate.get();
+
[webView _setVisibilityState:WebPageVisibilityStatePrerender isInitialState:YES];
}
void PageVisibilityStateWithWindowChanges::teardownView(WebView *webView)
{
- id uiDelegate = webView.UIDelegate;
+ EXPECT_TRUE(webView.UIDelegate == m_delegate.get());
webView.UIDelegate = nil;
- [uiDelegate release];
+ m_delegate = nil;
}
void PageVisibilityStateWithWindowChanges::initializeView(WKView *wkView)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes