From e9875fe54e1e8ae1db6e28eedeed2e3e51f8226b Mon Sep 17 00:00:00 2001 From: Lej77 <31554212+Lej77@users.noreply.github.com> Date: Mon, 3 Jul 2023 19:31:57 +0200 Subject: [PATCH] fix(windows): leak when updating tray icon or tooltip (#755) --- .changes/windows-fix-leak-on-update-tray.md | 5 +++++ src/platform_impl/windows/system_tray.rs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changes/windows-fix-leak-on-update-tray.md diff --git a/.changes/windows-fix-leak-on-update-tray.md b/.changes/windows-fix-leak-on-update-tray.md new file mode 100644 index 000000000..7c1aacae9 --- /dev/null +++ b/.changes/windows-fix-leak-on-update-tray.md @@ -0,0 +1,5 @@ +--- +"tao": "patch" +--- + +On Windows, fix leak of `tao::system_tray::Icon` when calling `tao::system_tray::SystemTray::set_icon` and leak of `String` when calling `tao::system_tray::SystemTray::set_tooltip`. diff --git a/src/platform_impl/windows/system_tray.rs b/src/platform_impl/windows/system_tray.rs index 0c46c2951..f44c5184c 100644 --- a/src/platform_impl/windows/system_tray.rs +++ b/src/platform_impl/windows/system_tray.rs @@ -274,12 +274,12 @@ unsafe extern "system" fn tray_subclass_proc( if msg == WM_USER_UPDATE_TRAYICON { let icon = wparam.0 as *mut Icon; - subclass_input.icon = (*icon).clone(); + subclass_input.icon = *Box::from_raw(icon); } if msg == WM_USER_UPDATE_TOOLTIP { let tooltip = wparam.0 as *mut String; - subclass_input.tooltip = Some((*tooltip).clone()); + subclass_input.tooltip = Some(*Box::from_raw(tooltip)); } if msg == *S_U_TASKBAR_RESTART {