Skip to content

Conversation

@Acumen-Desktop
Copy link

Fix WKWebView crash on tab close

Problem

When closing a WKWebView tab, the app crashes with signal 11 (SIGSEGV).

Root Cause

  1. Dangling pointer: The remove method was releasing the webview and then accessing it in an async dispatch_async block, causing a use-after-free
  2. KVO observer leak: The fullscreenState KVO observer was only removed in dealloc, but by then self.webView was already nil

Solution

  • Remove KVO observer first, before any cleanup
  • Remove webview from superview synchronously instead of async dispatch
  • Add safety checks in dealloc for already-removed observers

Testing

Tested by repeatedly opening and closing both CEF and WebKit tabs - no more crashes.

- Remove KVO observer before releasing the webview
- Remove from superview synchronously instead of async dispatch
- Add safety checks in dealloc for already-removed observers

This fixes a crash (signal 11) when closing WKWebView tabs caused by:
1. Dangling pointer after releaseObjCObject when accessing in async block
2. KVO observer not being removed before the webview was deallocated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant