Skip to content

fix(macos): prevent use-after-free in stop_task on macOS 11 during WKWebView dealloc#1734

Open
x93008 wants to merge 2 commits into
tauri-apps:devfrom
x93008:fix/macos/macos_11_crash
Open

fix(macos): prevent use-after-free in stop_task on macOS 11 during WKWebView dealloc#1734
x93008 wants to merge 2 commits into
tauri-apps:devfrom
x93008:fix/macos/macos_11_crash

Conversation

@x93008
Copy link
Copy Markdown

@x93008 x93008 commented May 21, 2026

macOS 11 WebKit bug: during WKWebView dealloc, stopAllTasksForPage calls stop_task with already-freed task pointers. Any access (including the implicit objc_release from objc2 reference types) causes SIGSEGV.

Fix:

  • stop_task: use raw pointers (*mut AnyObject) instead of objc2 references to skip automatic retain/release. Body is no-op since task is invalid.
  • start_task response handler: explicit drop(webview) before drop(task) to ensure correct deallocation order.

closes #1733

Details

On macOS 11, WebKit's internal stopAllTasksForPage (triggered during [WKWebView dealloc]) passes already-freed WKURLSchemeTask pointers to the webView:stopURLSchemeTask: callback. Using objc2 reference types (&WryWebView, &ProtocolObject<dyn WKURLSchemeTask>) triggers implicit objc_retain on entry, which crashes on the freed pointer.

The explicit drop ordering (drop(webview) before drop(task)) prevents a scenario where dropping Retained<WryWebView> on a worker thread triggers dealloc → stopAllTasksForPagestop_task, while the task reference is still alive in the closure.

This is the same class of race condition reported in tauri-apps/tauri#11516 (macOS 15) and #1730.

@x93008 x93008 requested a review from a team as a code owner May 21, 2026 02:14
macOS 11 WebKit bug: during WKWebView dealloc, stopAllTasksForPage calls
stop_task with already-freed task pointers. Any access (including the
implicit objc_release from objc2 reference types) causes SIGSEGV.

Fix:
- stop_task: use raw pointers (*mut AnyObject) instead of objc2 references
  to skip automatic retain/release. Body is no-op since task is invalid.
- start_task response handler: explicit drop(webview) before drop(task) to
  ensure correct deallocation order.
@x93008 x93008 force-pushed the fix/macos/macos_11_crash branch from 2c26a8b to e8cf34d Compare May 21, 2026 02:26
@Legend-Master Legend-Master added the ai-slop Low effort content, see https://github.com/tauri-apps/tauri?tab=contributing-ov-file#ai-tool-policy label May 21, 2026
@x93008
Copy link
Copy Markdown
Author

x93008 commented May 21, 2026

Tested Platforms

OS Version Result
macOS 11.7.10 (Big Sur)
macOS 12.7.3 (Monterey)
macOS 13.6 (Ventura)
macOS 14.2.1 (Sonoma)
macOS 15.7.2 (Sequoia)
macOS 26.4.1 (Tahoe)
Windows 10 22H2 (19045.5011)
Windows 11 25H2 (26200.8457)

All platforms pass without crash.

@x93008 x93008 force-pushed the fix/macos/macos_11_crash branch from e8cf34d to 9be1a6b Compare May 21, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-slop Low effort content, see https://github.com/tauri-apps/tauri?tab=contributing-ov-file#ai-tool-policy

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stop_task use-after-free crash on macOS 11 during WKWebView dealloc

2 participants