Peter Lapisu
Peter Lapisu

Reputation: 20975

OSX 10.10.3 crashes WebView on dealloc

After updating to 10.10.3 the WebView component started to crash after dealloc

- (void)dealloc {
    [self.webView.windowScriptObject setValue:nil forKey:@"CocoaApp"];
    [[self.webView mainFrame] stopLoading];
    [self.webView setUIDelegate:nil];
    [self.webView setEditingDelegate:nil];
    [self.webView setFrameLoadDelegate:nil];
    [self.webView setPolicyDelegate:nil];
    [self.webView removeFromSuperview];
}

The crash happens somewhere deep in WebView

EXC_BAD_ACCESS

1   0x7fff910bae9e WebDocumentLoaderMac::detachFromFrame()
2   0x7fff920288c0 WebCore::FrameLoader::detachFromParent()
3   0x7fff910d0e55 -[WebView(WebPrivate) _close]
4   0x7fff910d0c49 -[WebView dealloc]
5   0x7fff8b1cf89c objc_object::sidetable_release(bool)
6   0x7fff8b1b5e8f (anonymous namespace)::AutoreleasePoolPage::pop(void*)
7   0x7fff912b26f2 _CFAutoreleasePoolPop
8   0x7fff8830e762 -[NSAutoreleasePool drain]
9   0x7fff8e3f0cc1 -[NSApplication run]
10  0x7fff8e36d354 NSApplicationMain
11  0x1000ebb12 main
12  0x7fff8c81e5c9 start
13  0x3

Any ideas? Is this a Apple bug? It started AFTER 10.10.3?

It doesn't crash when NSZombie is enabled!

Upvotes: 3

Views: 583

Answers (2)

Jonathan
Jonathan

Reputation: 8812

I noticed you're using your own policy delegate:

[self.webView setPolicyDelegate:nil];

There's a known bug related to policy delegates in WebKit (only very recently fixed):

https://bugs.webkit.org/show_bug.cgi?id=144975

The short version is that you're probably hitting this assertion (which crashes the process with an intentional segfault):

https://github.com/WebKit/webkit/blob/24b1ae89efc10a4e6a6057b429c8e1d8d138a32f/Source/WebCore/loader/DocumentLoader.cpp#L935

because your policy handler (i.e. decidePolicyForMIMEType:request:frame:decisionListener:) is failing to make a policy decision (i.e not use, ignore, or download). The decision hangs around unmade, and when the loader eventually detaches it asserts that there are no pending policy decisions, which fails since the view is still waiting for a decision.

Upvotes: 1

Peter Lapisu
Peter Lapisu

Reputation: 20975

The fix i made, is not to release the webview, but hold a static reference into it (this is far from solving it and i contacted Apple regarding this issue)

#warning HOTFIX
{
    //this is because of http://stackoverflow.com/questions/29746074/osx-10-10-3-crashes-webview-on-dealloc
    static NSMutableArray * LIVE_FOR_EVER_WEBVIEW;

    if (LIVE_FOR_EVER_WEBVIEW == nil) {
        LIVE_FOR_EVER_WEBVIEW = [NSMutableArray new];
    }
    if (self.webView) {
        [LIVE_FOR_EVER_WEBVIEW addObject:self.webView];
    }
}

Upvotes: 1

Related Questions