From af0985080cad2531a60704b06304dad3f805f44c Mon Sep 17 00:00:00 2001 From: krishpranav Date: Sat, 11 Apr 2026 17:08:12 +0530 Subject: [PATCH 1/6] tauri-runtime-wry: avoid leaking ObjC retains in with_webview WebviewMessage::WithWebview converted Retained values to raw pointers with Retained::into_raw on Apple targets, transferring ownership without a corresponding release in this path. Use scoped Retained bindings and Retained::as_ptr for pointer handoff to the callback payload. This preserves borrowing semantics for callback lifetime and keeps Objective-C retain/release balanced when the retained values drop after callback return. Fixes #15210 --- crates/tauri-runtime-wry/src/lib.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index c48b742af2e7..a5bcb1d1d350 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -3903,25 +3903,28 @@ fn handle_user_message( #[cfg(target_os = "macos")] { use wry::WebViewExtMacOS; + let platform_webview = webview.webview(); + let manager = webview.manager(); + let ns_window = webview.ns_window(); f(Webview { - webview: Retained::into_raw(webview.webview()) as *mut objc2::runtime::AnyObject + webview: Retained::as_ptr(&platform_webview) as *const std::ffi::c_void as *mut std::ffi::c_void, - manager: Retained::into_raw(webview.manager()) as *mut objc2::runtime::AnyObject + manager: Retained::as_ptr(&manager) as *const std::ffi::c_void as *mut std::ffi::c_void, - ns_window: Retained::into_raw(webview.ns_window()) as *mut objc2::runtime::AnyObject + ns_window: Retained::as_ptr(&ns_window) as *const std::ffi::c_void as *mut std::ffi::c_void, }); } #[cfg(target_os = "ios")] { use wry::WebViewExtIOS; + let platform_webview = webview.inner.webview(); + let manager = webview.inner.manager(); f(Webview { - webview: Retained::into_raw(webview.inner.webview()) - as *mut objc2::runtime::AnyObject + webview: Retained::as_ptr(&platform_webview) as *const std::ffi::c_void as *mut std::ffi::c_void, - manager: Retained::into_raw(webview.inner.manager()) - as *mut objc2::runtime::AnyObject + manager: Retained::as_ptr(&manager) as *const std::ffi::c_void as *mut std::ffi::c_void, view_controller: window.ui_view_controller(), }); From b3f13c8ecc6a0d5638aae8979f8e5490ae8bbfc7 Mon Sep 17 00:00:00 2001 From: krishpranav Date: Sat, 11 Apr 2026 17:16:18 +0530 Subject: [PATCH 2/6] chore: add changes file for #15210 --- .changes/fix-objc-retain-leak.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .changes/fix-objc-retain-leak.md diff --git a/.changes/fix-objc-retain-leak.md b/.changes/fix-objc-retain-leak.md new file mode 100644 index 000000000000..9c5893821e77 --- /dev/null +++ b/.changes/fix-objc-retain-leak.md @@ -0,0 +1 @@ +patch tauri-runtime-wry From 9e7a52f9584f7b6f969d60a791f22f9fa606f328 Mon Sep 17 00:00:00 2001 From: krishpranav Date: Sat, 11 Apr 2026 18:55:25 +0530 Subject: [PATCH 3/6] changes: fix covector metadata for objc leak patch Format .changes/fix-objc-retain-leak.md with valid covector front matter and package bump metadata. This resolves CI failures in check-change-tags and covector status for this PR. --- .changes/fix-objc-retain-leak.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.changes/fix-objc-retain-leak.md b/.changes/fix-objc-retain-leak.md index 9c5893821e77..0c4951ab1db7 100644 --- a/.changes/fix-objc-retain-leak.md +++ b/.changes/fix-objc-retain-leak.md @@ -1 +1,5 @@ -patch tauri-runtime-wry +--- +"tauri-runtime-wry": patch:bug +--- + +Avoid leaking Objective-C objects in `WebviewMessage::WithWebview` on Apple targets by replacing `Retained::into_raw` with scoped retained bindings and `Retained::as_ptr` pointer handoff. From 7bc0dc5bd71189f3bfc39f61049cebd663b95f31 Mon Sep 17 00:00:00 2001 From: krishpranav Date: Thu, 9 Jul 2026 18:16:09 +0530 Subject: [PATCH 4/6] chore(tauri-runtime-wry): document Apple Webview pointer fields Add a doc/TODO note on the Apple with_webview pointer fields (webview/manager/ns_window/view_controller): they're borrowed from ObjC Retained handles and must not be mutated through, and should become *const c_void in v3. --- crates/tauri-runtime-wry/src/webview.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/tauri-runtime-wry/src/webview.rs b/crates/tauri-runtime-wry/src/webview.rs index 67b607392b88..69a7863a4fd3 100644 --- a/crates/tauri-runtime-wry/src/webview.rs +++ b/crates/tauri-runtime-wry/src/webview.rs @@ -17,6 +17,8 @@ mod imp { mod imp { use std::ffi::c_void; + // These pointers are borrowed from ObjC `Retained` handles owned elsewhere and must + // not be mutated through. TODO: change these to `*const c_void` in v3 (breaking change). pub struct Webview { pub webview: *mut c_void, pub manager: *mut c_void, From 9c3ef2d802cad8cb9a06368bde99020bb580d537 Mon Sep 17 00:00:00 2001 From: krishpranav Date: Thu, 9 Jul 2026 19:02:58 +0530 Subject: [PATCH 5/6] refactor(tauri-runtime-wry): simplify pointer cast in with_webview Apply Legend-Master's suggestion: use .cast_mut() instead of casting through *const c_void first, across all macOS/iOS with_webview fields. --- crates/tauri-runtime-wry/src/lib.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index a5bcb1d1d350..8a3da8d31fdc 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -3907,12 +3907,9 @@ fn handle_user_message( let manager = webview.manager(); let ns_window = webview.ns_window(); f(Webview { - webview: Retained::as_ptr(&platform_webview) as *const std::ffi::c_void - as *mut std::ffi::c_void, - manager: Retained::as_ptr(&manager) as *const std::ffi::c_void - as *mut std::ffi::c_void, - ns_window: Retained::as_ptr(&ns_window) as *const std::ffi::c_void - as *mut std::ffi::c_void, + webview: Retained::as_ptr(&platform_webview).cast_mut() as *mut std::ffi::c_void, + manager: Retained::as_ptr(&manager).cast_mut() as *mut std::ffi::c_void, + ns_window: Retained::as_ptr(&ns_window).cast_mut() as *mut std::ffi::c_void, }); } #[cfg(target_os = "ios")] @@ -3922,10 +3919,8 @@ fn handle_user_message( let manager = webview.inner.manager(); f(Webview { - webview: Retained::as_ptr(&platform_webview) as *const std::ffi::c_void - as *mut std::ffi::c_void, - manager: Retained::as_ptr(&manager) as *const std::ffi::c_void - as *mut std::ffi::c_void, + webview: Retained::as_ptr(&platform_webview).cast_mut() as *mut std::ffi::c_void, + manager: Retained::as_ptr(&manager).cast_mut() as *mut std::ffi::c_void, view_controller: window.ui_view_controller(), }); } From a7d33634a9148f73200ff9de4ecec9af70ae3001 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 9 Jul 2026 21:49:39 +0800 Subject: [PATCH 6/6] Add tauri in change file so it shows up there --- .changes/fix-objc-retain-leak.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changes/fix-objc-retain-leak.md b/.changes/fix-objc-retain-leak.md index 0c4951ab1db7..d24a6169038a 100644 --- a/.changes/fix-objc-retain-leak.md +++ b/.changes/fix-objc-retain-leak.md @@ -1,4 +1,5 @@ --- +"tauri": patch:bug "tauri-runtime-wry": patch:bug ---