From 6add778a08723f91748a742099b70aa911437f35 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Thu, 5 Jul 2012 19:55:52 +0200 Subject: [PATCH 1/1] PsppireVarSheet: Keep reference to the return value of _get_ui_manager 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 | 15 ++++++++++++--- src/ui/gui/psppire-var-sheet.h | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ui/gui/psppire-var-sheet.c b/src/ui/gui/psppire-var-sheet.c index 3a8f42397c..930c27797f 100644 --- a/src/ui/gui/psppire-var-sheet.c +++ b/src/ui/gui/psppire-var-sheet.c @@ -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; } diff --git a/src/ui/gui/psppire-var-sheet.h b/src/ui/gui/psppire-var-sheet.h index b115b9bb6b..754dd25892 100644 --- a/src/ui/gui/psppire-var-sheet.h +++ b/src/ui/gui/psppire-var-sheet.h @@ -73,6 +73,8 @@ struct _PsppireVarSheet GtkWidget *container; gulong on_switch_page_handler; + GtkUIManager *uim; + gboolean dispose_has_run; }; -- 2.30.2