[nautilus] dbus-launcher: Cleanup dbus-launcher creation and freeing



commit 151d482dff874a904f66ce878ad77445e08d925f
Author: Corey Berla <corey berla me>
Date:   Sun Jul 31 15:35:47 2022 -0700

    dbus-launcher: Cleanup dbus-launcher creation and freeing
    
    nautilus_dbus_launcher_finalize() attempts to free all apps, but
    it's possible that they haven't all been created yet (or in the wrong
    order).  Keep track of the last app to be created so that we only
    free created apps.

 src/nautilus-dbus-launcher.c | 17 +++++++++++------
 src/nautilus-dbus-launcher.h |  1 +
 2 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/src/nautilus-dbus-launcher.c b/src/nautilus-dbus-launcher.c
index 25ec3930b..743b18a37 100644
--- a/src/nautilus-dbus-launcher.c
+++ b/src/nautilus-dbus-launcher.c
@@ -24,6 +24,7 @@ struct _NautilusDBusLauncher
 {
     GObject parent;
 
+    NautilusDBusLauncherApp last_app_initialized;
     NautilusDBusLauncherData *data[NAUTILUS_DBUS_LAUNCHER_N_APPS];
 };
 
@@ -165,7 +166,7 @@ nautilus_dbus_launcher_finalize (GObject *object)
 {
     NautilusDBusLauncher *self = NAUTILUS_DBUS_LAUNCHER (object);
 
-    for (gint i = 0; i < NAUTILUS_DBUS_LAUNCHER_N_APPS - 1; i++)
+    for (gint i = 1; i <= self->last_app_initialized; i++)
     {
         g_clear_object (&self->data[i]->proxy);
         g_clear_object (&self->data[i]->error);
@@ -187,10 +188,13 @@ nautilus_dbus_launcher_class_init (NautilusDBusLauncherClass *klass)
     object_class->finalize = nautilus_dbus_launcher_finalize;
 }
 
-static NautilusDBusLauncherData *
-nautilus_dbus_launcher_data_new (gboolean ping_on_creation)
+static void
+nautilus_dbus_launcher_data_init (NautilusDBusLauncher    *self,
+                                  NautilusDBusLauncherApp  app,
+                                  gboolean                 ping_on_creation)
 {
     NautilusDBusLauncherData *data;
+    g_assert_true (app == self->last_app_initialized + 1);
 
     data = g_new0 (NautilusDBusLauncherData, 1);
     data->proxy = NULL;
@@ -198,14 +202,15 @@ nautilus_dbus_launcher_data_new (gboolean ping_on_creation)
     data->ping_on_creation = ping_on_creation;
     data->cancellable = g_cancellable_new ();
 
-    return data;
+    self->data[app] = data;
+    self->last_app_initialized = app;
 }
 
 static void
 nautilus_dbus_launcher_init (NautilusDBusLauncher *self)
 {
-    self->data[NAUTILUS_DBUS_LAUNCHER_SETTINGS] = nautilus_dbus_launcher_data_new (FALSE);
-    self->data[NAUTILUS_DBUS_LAUNCHER_DISKS] = nautilus_dbus_launcher_data_new (TRUE);
+    nautilus_dbus_launcher_data_init (self, NAUTILUS_DBUS_LAUNCHER_SETTINGS, FALSE);
+    nautilus_dbus_launcher_data_init (self, NAUTILUS_DBUS_LAUNCHER_DISKS, TRUE);
 
     nautilus_dbus_launcher_create_proxy (self->data[NAUTILUS_DBUS_LAUNCHER_SETTINGS],
                                          "org.gnome.Settings", "/org/gnome/Settings",
diff --git a/src/nautilus-dbus-launcher.h b/src/nautilus-dbus-launcher.h
index 60f4233c7..8d5552d95 100644
--- a/src/nautilus-dbus-launcher.h
+++ b/src/nautilus-dbus-launcher.h
@@ -17,6 +17,7 @@ G_DECLARE_FINAL_TYPE (NautilusDBusLauncher, nautilus_dbus_launcher, NAUTILUS, DB
 
 
 typedef enum {
+    NAUTILUS_DBUS_APP_0,
     NAUTILUS_DBUS_LAUNCHER_SETTINGS,
     NAUTILUS_DBUS_LAUNCHER_DISKS,
     NAUTILUS_DBUS_LAUNCHER_N_APPS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]