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(linux): Use after free in TrayIconBuilder::with_menu (#89) #103

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/platform_impl/gtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct TrayIcon {
temp_dir_path: Option<PathBuf>,
path: PathBuf,
counter: u32,
menu: Option<Box<dyn muda::ContextMenu>>,
}

impl TrayIcon {
Expand All @@ -34,7 +35,7 @@ impl TrayIcon {
indicator.set_icon_theme_path(&parent_path.to_string_lossy());
indicator.set_icon_full(&icon_path.to_string_lossy(), "icon");

if let Some(menu) = attrs.menu {
if let Some(menu) = &attrs.menu {
indicator.set_menu(&mut menu.gtk_context_menu());
}

Expand All @@ -48,6 +49,7 @@ impl TrayIcon {
path: icon_path,
temp_dir_path: attrs.temp_dir_path,
counter: 0,
menu: attrs.menu,
})
}
pub fn set_icon(&mut self, icon: Option<Icon>) -> crate::Result<()> {
Expand All @@ -72,9 +74,10 @@ impl TrayIcon {
}

pub fn set_menu(&mut self, menu: Option<Box<dyn crate::menu::ContextMenu>>) {
if let Some(menu) = menu {
if let Some(menu) = &menu {
self.indicator.set_menu(&mut menu.gtk_context_menu());
}
self.menu = menu;
}

pub fn set_tooltip<S: AsRef<str>>(&mut self, _tooltip: Option<S>) -> crate::Result<()> {
Expand Down