Skip to content

Commit

Permalink
Fix reference cycle
Browse files Browse the repository at this point in the history
Only capture a weak reference to application in DBus closure, to break
the app -> connection -> closure -> app reference cycle.
  • Loading branch information
swsnr committed Jan 23, 2025
1 parent 6f6f7a4 commit f434cfd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/app/searchprovider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! Utilities for the search provider of Turn On.
use glib::{dpgettext2, ControlFlow, Variant, VariantDict};
use gtk::gio::{ListStore, Notification, NotificationPriority, RegistrationId};
use gtk::gio::{DBusError, ListStore, Notification, NotificationPriority, RegistrationId};
use gtk::prelude::*;

use crate::app::TurnOnApplication;
Expand Down Expand Up @@ -143,10 +143,12 @@ fn get_result_metas(app: &TurnOnApplication, call: &GetResultMetas) -> Variant {
}

async fn dispatch_method_call(
app: TurnOnApplication,
app: Option<TurnOnApplication>,
call: MethodCall,
) -> Result<Option<Variant>, glib::Error> {
use MethodCall::*;
let app =
app.ok_or_else(|| glib::Error::new(DBusError::Disconnected, "Application is gone"))?;
match call {
GetInitialResultSet(c) => {
glib::trace!("Initial search for terms {:?}", c.terms);
Expand Down Expand Up @@ -184,7 +186,7 @@ pub fn register_app_search_provider(app: &TurnOnApplication) -> Option<Registrat
.register_object("/de/swsnr/turnon/search", &interface_info)
.typed_method_call::<searchprovider2::MethodCall>()
.invoke_and_return_future_local(glib::clone!(
#[strong]
#[weak_allow_none]
app,
move |_, sender, call| {
glib::debug!("Sender {sender:?} called method {call:?}");
Expand Down

0 comments on commit f434cfd

Please sign in to comment.