From 36b985e939f4769f9835b4865ee1013229ec7539 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sun, 3 Apr 2022 06:33:44 -0700 Subject: [PATCH] fix(macos): custom protocol memory leak (#539) --- .changes/fix-macos-protocol-memory-leak.md | 5 +++++ examples/stream_range.rs | 2 +- src/webview/wkwebview/mod.rs | 10 ++++------ 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 .changes/fix-macos-protocol-memory-leak.md diff --git a/.changes/fix-macos-protocol-memory-leak.md b/.changes/fix-macos-protocol-memory-leak.md new file mode 100644 index 000000000..da7590247 --- /dev/null +++ b/.changes/fix-macos-protocol-memory-leak.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +Fixes a memory leak on the custom protocol response body on macOS. diff --git a/examples/stream_range.rs b/examples/stream_range.rs index 726b64926..95f4b4eaa 100644 --- a/examples/stream_range.rs +++ b/examples/stream_range.rs @@ -22,7 +22,7 @@ fn main() -> wry::Result<()> { let video_file = PathBuf::from("examples/test_video.mp4"); let video_url = - "http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_30fps_normal.mp4"; + "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; if !video_file.exists() { // Downloading with curl this saves us from adding diff --git a/src/webview/wkwebview/mod.rs b/src/webview/wkwebview/mod.rs index cd9587364..071adf887 100644 --- a/src/webview/wkwebview/mod.rs +++ b/src/webview/wkwebview/mod.rs @@ -9,12 +9,9 @@ mod web_context; pub use web_context::WebContextImpl; #[cfg(target_os = "macos")] +use cocoa::appkit::{NSView, NSViewHeightSizable, NSViewWidthSizable}; use cocoa::{ - appkit::{NSView, NSViewHeightSizable, NSViewWidthSizable}, - base::YES, -}; -use cocoa::{ - base::id, + base::{id, YES}, foundation::{NSDictionary, NSFastEnumeration, NSInteger}, }; @@ -186,7 +183,8 @@ impl InnerWebView { // Send data let bytes = content.as_ptr() as *mut c_void; let data: id = msg_send![class!(NSData), alloc]; - let data: id = msg_send![data, initWithBytes:bytes length:content.len()]; + let data: id = + msg_send![data, initWithBytesNoCopy:bytes length:content.len() freeWhenDone: YES]; let () = msg_send![task, didReceiveData: data]; } else { let urlresponse: id = msg_send![class!(NSHTTPURLResponse), alloc];