Audit and cleanup dispose methods of classes which have them.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 4 Jul 2020 09:30:29 +0000 (11:30 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 4 Jul 2020 09:30:29 +0000 (11:30 +0200)
Ensure that all non-trivial dispose methods use the dispose_has_run
flag and that only unreffing takes place within dispose.

13 files changed:
src/ui/gui/psppire-acr.c
src/ui/gui/psppire-acr.h
src/ui/gui/psppire-conf.c
src/ui/gui/psppire-conf.h
src/ui/gui/psppire-data-editor.c
src/ui/gui/psppire-data-editor.h
src/ui/gui/psppire-data-window.c
src/ui/gui/psppire-data-window.h
src/ui/gui/psppire-dict.c
src/ui/gui/psppire-dict.h
src/ui/gui/psppire-scanf.c
src/ui/gui/psppire-window-register.c
src/ui/gui/psppire-window-register.h

index b858df268eb904ac927576af39b47b4efc3db74b..a876413fd582e5b7dd137b742c4314e811c3b7be 100644 (file)
@@ -50,6 +50,11 @@ static void
 psppire_acr_dispose (GObject *obj)
 {
   PsppireAcr *acr = PSPPIRE_ACR (obj);
+
+  if (acr->dispose_has_run)
+    return;
+  acr->dispose_has_run = TRUE;
+
   psppire_acr_set_model (acr, NULL);
 
   G_OBJECT_CLASS (psppire_acr_parent_class)->dispose (obj);
@@ -259,6 +264,8 @@ psppire_acr_init (PsppireAcr *acr)
 
   GtkWidget *sw = gtk_scrolled_window_new (NULL, NULL);
 
+  acr->dispose_has_run = FALSE;
+
   gtk_orientable_set_orientation (GTK_ORIENTABLE (acr), GTK_ORIENTATION_HORIZONTAL);
 
   acr->tv = GTK_TREE_VIEW (gtk_tree_view_new ());
index 73873df356ef2502dcfbdd07481d0b1609fa9a71..c38f3f5f3a64d0e479d8361bf93953037031c47f 100644 (file)
@@ -66,7 +66,7 @@ struct _PsppireAcr
 {
   GtkBox parent;
 
-
+  gboolean dispose_has_run;
   GtkListStore *list_store;
 
   GtkTreeView *tv;
index 2629fdcfc00b668f38b46ce3784283a5e0e316a0..835d58c127bbbd850592cbf697c1fd73e3bc99b0 100644 (file)
@@ -148,7 +148,6 @@ psppire_conf_class_init (PsppireConfClass *class)
   object_class->finalize = psppire_conf_finalize;
   object_class->dispose = psppire_conf_dispose;
   object_class->constructor = psppire_conf_construct;
-
 }
 
 
@@ -169,7 +168,6 @@ psppire_conf_init (PsppireConf *conf)
 
   conf->keyfile = g_key_file_new ();
 
-  conf->dispose_has_run = FALSE;
   conf->idle = 0;
 }
 
index 5f4b283af5c2cf0f87bc9ccdd0d2d27aa8ff2902..de8db9397da3b650af9b7b53572b11884ef40295 100644 (file)
@@ -58,7 +58,6 @@ struct _PsppireConf
   GObject parent;
 
   /*< private >*/
-  gboolean dispose_has_run ;
 
   GKeyFile *keyfile;
   gchar *filename;
index 181e5cbf3d40a1124463a8631e5d63532cb13959..e852b7d92b403d2d1647c7ea8b863cddd648def5 100644 (file)
@@ -83,6 +83,10 @@ static GObjectClass * parent_class = NULL;
 static void
 psppire_data_editor_finalize (GObject *obj)
 {
+  PsppireDataEditor *de = (PsppireDataEditor *) obj;
+  if (de->font)
+    pango_font_description_free (de->font);
+
   /* Chain up to the parent class */
   G_OBJECT_CLASS (parent_class)->finalize (obj);
 }
@@ -92,23 +96,13 @@ psppire_data_editor_dispose (GObject *obj)
 {
   PsppireDataEditor *de = (PsppireDataEditor *) obj;
 
-  if (de->data_store)
-    {
-      g_object_unref (de->data_store);
-      de->data_store = NULL;
-    }
+  if (de->dispose_has_run)
+    return;
 
-  if (de->dict)
-    {
-      g_object_unref (de->dict);
-      de->dict = NULL;
-    }
+  de->dispose_has_run = TRUE;
 
-  if (de->font != NULL)
-    {
-      pango_font_description_free (de->font);
-      de->font = NULL;
-    }
+  g_object_unref (de->data_store);
+  g_object_unref (de->dict);
 
   /* Chain up to the parent class */
   G_OBJECT_CLASS (parent_class)->dispose (obj);
@@ -491,6 +485,8 @@ psppire_data_editor_init (PsppireDataEditor *de)
   GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (de));
   gtk_style_context_add_class (context, "psppire-data-editor");
 
+  de->dispose_has_run = FALSE;
+
   de->font = NULL;
 
   g_object_set (de, "tab-pos", GTK_POS_BOTTOM, NULL);
index 88d07a811411b78f381ed939d2e19379be316d6b..a5152bb759cbb2ea47fc362b1cc5d1321d45a0fc 100644 (file)
@@ -51,6 +51,8 @@ struct _PsppireDataEditor
 {
   GtkNotebook parent;
 
+  gboolean dispose_has_run;
+
   /* <private> */
   PsppireDataStore *data_store;
   PsppireDict *dict;
index 2fffd790a58cbc388f04c543b89eff6ebe23a3e3..811d5e9eb8825bd52d4922e787773fb6f5b9132c 100644 (file)
@@ -958,9 +958,11 @@ enable_save (PsppireDataWindow *dw)
    modify the menu as part of the "filename" property_set() function and end up
    with a Gtk-CRITICAL since 'menu' is NULL.  */
 static void
-psppire_data_window_init (PsppireDataWindow *de)
+psppire_data_window_init (PsppireDataWindow *dw)
 {
-  de->builder = builder_new ("data-editor.ui");
+  dw->dispose_has_run = FALSE;
+
+  dw->builder = builder_new ("data-editor.ui");
 }
 
 static void
@@ -1803,11 +1805,11 @@ psppire_data_window_dispose (GObject *object)
 {
   PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (object);
 
-  if (dw->builder != NULL)
-    {
-      g_object_unref (dw->builder);
-      dw->builder = NULL;
-    }
+  if (dw->dispose_has_run)
+    return;
+  dw->dispose_has_run = TRUE;
+
+  g_object_unref (dw->builder);
 
   if (dw->dict)
     {
@@ -1821,20 +1823,9 @@ psppire_data_window_dispose (GObject *object)
                                             G_CALLBACK (on_split_change), dw);
 
       g_object_unref (dw->dict);
-      dw->dict = NULL;
     }
 
-  if (dw->data_store)
-    {
-      g_object_unref (dw->data_store);
-      dw->data_store = NULL;
-    }
-
-  if (dw->ll.next != NULL)
-    {
-      ll_remove (&dw->ll);
-      dw->ll.next = NULL;
-    }
+  g_object_unref (dw->data_store);
 
   if (G_OBJECT_CLASS (parent_class)->dispose)
     G_OBJECT_CLASS (parent_class)->dispose (object);
@@ -1857,6 +1848,12 @@ psppire_data_window_finalize (GObject *object)
       dataset_destroy (dataset);
     }
 
+  if (dw->ll.next != NULL)
+    {
+      ll_remove (&dw->ll);
+      dw->ll.next = NULL;
+    }
+
   if (G_OBJECT_CLASS (parent_class)->finalize)
     G_OBJECT_CLASS (parent_class)->finalize (object);
 }
index a632c8d1121f946db80a2b410edc3c7241e78c81..61ff409ac790e7c1724bc8303304f87708217e99 100644 (file)
@@ -62,6 +62,8 @@ struct _PsppireDataWindow
 {
   PsppireWindow parent;
 
+  gboolean dispose_has_run;
+
   /* <private> */
   PsppireDataEditor *data_editor;
   GtkBuilder *builder;
index 87d13bc6e4d8db45468ad7c6e81055718c2b0a0c..e381e5dab7a40050df1a47f89e33564ded7341f6 100644 (file)
@@ -287,6 +287,11 @@ psppire_dict_dispose (GObject *object)
 {
   PsppireDict *d = PSPPIRE_DICT (object);
 
+  if (!d->dispose_has_run)
+    return;
+
+  d->dispose_has_run = TRUE;
+
   dict_set_callbacks (d->dict, NULL, NULL);
   dict_unref (d->dict);
 
@@ -352,10 +357,12 @@ static const struct dict_callbacks gui_callbacks =
   };
 
 static void
-psppire_dict_init (PsppireDict *psppire_dict)
+psppire_dict_init (PsppireDict *d)
 {
-  psppire_dict->stamp = g_random_int ();
-  psppire_dict->disable_insert_signal = FALSE;
+  d->dispose_has_run = FALSE;
+
+  d->stamp = g_random_int ();
+  d->disable_insert_signal = FALSE;
 }
 
 /**
index 2c88a49492a0fa49e4cfb2ad7fb4595544fc665d..c3674b13300130593eff77539690187a2abe6558 100644 (file)
@@ -61,6 +61,8 @@ struct _PsppireDict
   GObject             parent;
   struct dictionary   *dict;
 
+  gboolean dispose_has_run;
+
   gboolean disable_insert_signal;
   /* For GtkTreeModelIface */
   gint stamp;
index 951b27357f059ee94e79ef9d4be2f443ee9e6e25..e91b03ee1d93dcdfbd56d51d7fd853319848a82a 100644 (file)
@@ -331,6 +331,8 @@ psppire_scanf_class_init (PsppireScanfClass *class)
 static void
 psppire_scanf_init (PsppireScanf *w)
 {
+  w->dispose_has_run = FALSE;
+
   gtk_orientable_set_orientation (GTK_ORIENTABLE (w), GTK_ORIENTATION_HORIZONTAL);
 }
 
index 6bb2b7cb2f0e6b7934bb4976621a3f0c723a72b4..66e7353fb107abc7eeae56cd4a1d25e860f3968d 100644 (file)
@@ -134,7 +134,6 @@ psppire_window_register_class_init (PsppireWindowRegisterClass *class)
 static void
 psppire_window_register_init (PsppireWindowRegister *window_register)
 {
-  window_register->dispose_has_run = FALSE;
   window_register->name_table = g_hash_table_new (g_str_hash, g_str_equal);
 }
 
index cf4f4d8ec9a41773fae12e9e2cf8e85069a554d6..fdc6551926020f7482a40cf35ffac55076468792 100644 (file)
@@ -58,7 +58,6 @@ struct _PsppireWindowRegister
   GObject parent;
 
   /*< private >*/
-  gboolean dispose_has_run ;
   GHashTable *name_table;
 };