From c5714580a957aac167ea5535c7ba87bdba949b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Bonithon?= Date: Mon, 11 Sep 2023 06:53:31 +0200 Subject: [PATCH] Properly finalize global objects in main --- src/app-manager.c | 2 ++ src/main.c | 7 ++++++- src/process-window.c | 13 +++---------- src/settings.c | 16 ++++++++++++++++ src/task-manager.c | 2 ++ 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/app-manager.c b/src/app-manager.c index b2bdb0c..21dcf00 100644 --- a/src/app-manager.c +++ b/src/app-manager.c @@ -92,6 +92,8 @@ static void xtm_app_manager_finalize (GObject *object) { g_array_free (XTM_APP_MANAGER (object)->apps, TRUE); + + G_OBJECT_CLASS (xtm_app_manager_parent_class)->finalize (object); } static GPid diff --git a/src/main.c b/src/main.c index 77798b5..09ab31b 100644 --- a/src/main.c +++ b/src/main.c @@ -264,7 +264,7 @@ int main (int argc, char *argv[]) xtm_settings_bind_xfconf (settings, channel); show_hide_status_icon (); - window = xtm_process_window_new (); + window = g_object_ref_sink (xtm_process_window_new ()); if (!start_hidden) gtk_widget_show (window); @@ -288,6 +288,11 @@ int main (int argc, char *argv[]) else g_warning ("Nothing to do: activate hiding to the notification area when using --start-hidden"); + g_object_unref (task_manager); + g_object_unref (window); + g_object_unref (settings); + if (status_icon_or_null != NULL) + g_object_unref (status_icon_or_null); xfconf_shutdown(); return 0; diff --git a/src/process-window.c b/src/process-window.c index 6e7d0ae..0f621a7 100644 --- a/src/process-window.c +++ b/src/process-window.c @@ -388,17 +388,10 @@ xtm_process_window_finalize (GObject *object) { XtmProcessWindow *window = XTM_PROCESS_WINDOW (object); - if (GTK_IS_TREE_VIEW (window->treeview)) - gtk_widget_destroy (window->treeview); - - if (GTK_IS_BOX (window->statusbar)) - gtk_widget_destroy (window->statusbar); - - if (XTM_IS_SETTINGS (window->settings)) - g_object_unref (window->settings); - + g_object_unref (window->settings); g_object_unref (window->builder); - window->builder = NULL; + + G_OBJECT_CLASS (xtm_process_window_parent_class)->finalize (object); } /** diff --git a/src/settings.c b/src/settings.c index 58774c0..83cf022 100644 --- a/src/settings.c +++ b/src/settings.c @@ -74,6 +74,7 @@ G_DEFINE_TYPE (XtmSettings, xtm_settings, G_TYPE_OBJECT) static void xtm_settings_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec); static void xtm_settings_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); +static void xtm_settings_finalize (GObject *object); static void xtm_settings_class_init (XtmSettingsClass *klass) @@ -82,6 +83,7 @@ xtm_settings_class_init (XtmSettingsClass *klass) xtm_settings_parent_class = g_type_class_peek_parent (klass); class->get_property = xtm_settings_get_property; class->set_property = xtm_settings_set_property; + class->finalize = xtm_settings_finalize; g_object_class_install_property (class, PROP_SHOW_ALL_PROCESSES, g_param_spec_boolean ("show-all-processes", "ShowAllProcesses", "Show all processes", FALSE, G_PARAM_READWRITE)); g_object_class_install_property (class, PROP_SHOW_LEGEND, @@ -155,6 +157,20 @@ xtm_settings_set_property (GObject *object, guint property_id, const GValue *val } } +static void +xtm_settings_finalize (GObject *object) +{ + XtmSettings *settings = XTM_SETTINGS (object); + + for (gint i = 0; i < N_PROPS; i++) + { + if (G_IS_VALUE (settings->values + i)) + g_value_unset (settings->values + i); + } + + G_OBJECT_CLASS (xtm_settings_parent_class)->finalize (object); +} + void xtm_settings_bind_xfconf (XtmSettings *settings, XfconfChannel *channel) { diff --git a/src/task-manager.c b/src/task-manager.c index 7e9ec9f..0e91602 100644 --- a/src/task-manager.c +++ b/src/task-manager.c @@ -119,6 +119,8 @@ xtm_task_manager_finalize (GObject *object) } #endif g_object_unref (settings); + + G_OBJECT_CLASS (xtm_task_manager_parent_class)->finalize (object); } static void