Skip to content

Commit

Permalink
fix(macos): custom protocol memory leak (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Apr 3, 2022
1 parent 313eaea commit 36b985e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
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

0 comments on commit 36b985e

Please sign in to comment.