PsppireVarSheet: Keep reference to the return value of _get_ui_manager
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 5 Jul 2012 17:55:52 +0000 (19:55 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sun, 8 Jul 2012 09:57:31 +0000 (11:57 +0200)
I changed the var_sheett to keep a reference to the uim object which it
returns from the _get_ui_manager objects.  This avoids a problem where
the object was getting its last reference unreffed by another object.

src/ui/gui/psppire-var-sheet.c
src/ui/gui/psppire-var-sheet.h

index 3a8f42397c182929f04a96703e37fbad6792bbc1..930c27797ff8c0b2d5ec0da37567d7e5e1bc0c38 100644 (file)
@@ -926,6 +926,8 @@ psppire_var_sheet_dispose (GObject *obj)
   if (var_sheet->dict)
     g_object_unref (var_sheet->dict);
   
+  if (var_sheet->uim)
+    g_object_unref (var_sheet->uim);
 
   /* These dialogs are not GObjects (although they should be!)
     But for now, unreffing them only causes a GCritical Error
@@ -1168,6 +1170,7 @@ psppire_var_sheet_init (PsppireVarSheet *obj)
 
   obj->container = NULL;
   obj->dispose_has_run = FALSE;
+  obj->uim = NULL;
 
   pspp_sheet_view_append_column (sheet_view, make_row_number_column (obj));
 
@@ -1418,8 +1421,14 @@ psppire_var_sheet_goto_variable (PsppireVarSheet *var_sheet, int dict_index)
 GtkUIManager *
 psppire_var_sheet_get_ui_manager (PsppireVarSheet *var_sheet)
 {
-  return GTK_UI_MANAGER (get_object_assert (var_sheet->builder,
-                                            "var_sheet_uim",
-                                            GTK_TYPE_UI_MANAGER));
+  if (var_sheet->uim == NULL)
+    {
+      var_sheet->uim = GTK_UI_MANAGER (get_object_assert (var_sheet->builder,
+                                                         "var_sheet_uim",
+                                                         GTK_TYPE_UI_MANAGER));
+      g_object_ref (var_sheet->uim);
+    }
+
+  return var_sheet->uim;
 }
 
index b115b9bb6be5dc7da9e6375884d7a6b4a640367c..754dd258928b46143503da9808a9381f752b0503 100644 (file)
@@ -73,6 +73,8 @@ struct _PsppireVarSheet
   GtkWidget *container;
   gulong on_switch_page_handler;
 
+  GtkUIManager *uim;
+
   gboolean dispose_has_run;
 };