Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(macos): custom protocol memory leak #539

Merged
merged 1 commit into from Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .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.
2 changes: 1 addition & 1 deletion examples/stream_range.rs
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions src/webview/wkwebview/mod.rs
Expand Up @@ -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},
};

Expand Down Expand Up @@ -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];
Expand Down