Skip to content

Commit 4c09a0f

Browse files
committed
Bug 799249 - Crash while switch to recently opened file
Null the model's root account so that it can't be traversed after it has been disposed.
1 parent 5f70178 commit 4c09a0f

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

gnucash/gnome-utils/gnc-tree-model-account.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,11 @@ gnc_tree_model_account_init (GncTreeModelAccount *model)
199199
static void
200200
gnc_tree_model_account_finalize (GObject *object)
201201
{
202-
GncTreeModelAccount *model;
203-
204202
g_return_if_fail (object != NULL);
205203
g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(object));
206204

207205
ENTER("model %p", object);
208206

209-
model = GNC_TREE_MODEL_ACCOUNT(object);
210-
211-
model->book = NULL;
212-
213207
G_OBJECT_CLASS(gnc_tree_model_account_parent_class)->finalize (object);
214208
LEAVE(" ");
215209
}
@@ -242,6 +236,9 @@ gnc_tree_model_account_dispose (GObject *object)
242236
gnc_tree_model_account_update_color,
243237
model);
244238

239+
model->book = NULL;
240+
model->root = NULL;
241+
245242
G_OBJECT_CLASS(gnc_tree_model_account_parent_class)->dispose (object);
246243
LEAVE(" ");
247244
}
@@ -429,6 +426,12 @@ gnc_tree_model_account_get_iter (GtkTreeModel *tree_model,
429426

430427
model = GNC_TREE_MODEL_ACCOUNT(tree_model);
431428

429+
if (!model->root)
430+
{
431+
LEAVE("No root account");
432+
return FALSE;
433+
}
434+
432435
if (gtk_tree_path_get_depth (path) <= 0)
433436
{
434437
LEAVE("bad depth");
@@ -1409,7 +1412,7 @@ gnc_tree_model_account_event_handler (QofInstance *entity,
14091412
Account *account, *parent;
14101413

14111414
g_return_if_fail (model); /* Required */
1412-
1415+
g_return_if_fail (model->root); /* Either disposed or not initialized. */
14131416
if (!GNC_IS_ACCOUNT(entity))
14141417
return;
14151418

gnucash/gnome-utils/gnc-tree-view-account.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
static QofLogModule log_module = GNC_MOD_GUI;
5959

6060
/** Declarations *********************************************************/
61+
static void gnc_tree_view_account_destroy (GtkWidget *widget);
6162
static void gnc_tree_view_account_finalize (GObject *object);
6263
static gboolean gnc_tree_view_search_compare (GtkTreeModel *model, gint column,
6364
const gchar *key, GtkTreeIter *iter, gpointer search_data);
@@ -129,10 +130,11 @@ G_DEFINE_TYPE(GncTreeViewAccount, gnc_tree_view_account, GNC_TYPE_TREE_VIEW)
129130
static void
130131
gnc_tree_view_account_class_init (GncTreeViewAccountClass *klass)
131132
{
132-
GObjectClass *o_class;
133-
133+
GObjectClass *o_class = G_OBJECT_CLASS (klass);
134+
GtkWidgetClass *w_class = GTK_WIDGET_CLASS (klass);
134135
/* GObject signals */
135-
o_class = G_OBJECT_CLASS (klass);
136+
137+
w_class->destroy = gnc_tree_view_account_destroy;
136138
o_class->finalize = gnc_tree_view_account_finalize;
137139

138140
gnc_hook_add_dangler(HOOK_CURRENCY_CHANGED,
@@ -167,6 +169,21 @@ gnc_tree_view_account_init (GncTreeViewAccount *view)
167169
gnc_init_account_view_info(&view->avi);
168170
}
169171

172+
static void
173+
gnc_tree_view_account_destroy (GtkWidget *widget)
174+
{
175+
176+
GtkTreeView *view = GTK_TREE_VIEW (widget);
177+
if (view)
178+
{
179+
GtkTreeModel *model;
180+
model = gtk_tree_view_get_model(view);
181+
g_object_run_dispose (G_OBJECT (model));
182+
gtk_tree_view_set_model(view, NULL);
183+
}
184+
GTK_WIDGET_CLASS(gnc_tree_view_account_parent_class)->destroy(widget);
185+
}
186+
170187
static void
171188
gnc_tree_view_account_finalize (GObject *object)
172189
{

gnucash/gnome/gnc-plugin-page-account-tree.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,8 @@ gnc_plugin_page_account_tree_destroy_widget (GncPluginPage *plugin_page)
770770
// Save account filter state information to account section
771771
gnc_tree_view_account_save_filter (GNC_TREE_VIEW_ACCOUNT(priv->tree_view), &priv->fd,
772772
gnc_state_get_current(), gnc_tree_view_get_state_section (GNC_TREE_VIEW(priv->tree_view)));
773+
g_object_unref(G_OBJECT(priv->tree_view));
774+
priv->tree_view = NULL;
773775

774776
// Destroy the filter override hash table
775777
g_hash_table_destroy(priv->fd.filter_override);
@@ -780,10 +782,10 @@ gnc_plugin_page_account_tree_destroy_widget (GncPluginPage *plugin_page)
780782
// Remove the page focus idle function if present
781783
g_idle_remove_by_data (plugin_page);
782784

783-
if (priv->widget)
785+
if (priv->tree_view)
784786
{
785-
g_object_unref(G_OBJECT(priv->widget));
786-
priv->widget = NULL;
787+
gtk_widget_destroy(GTK_WIDGET(priv->tree_view));
788+
priv->tree_view = NULL;
787789
}
788790

789791
if (priv->component_id)

gnucash/report/commodity-utilities.scm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,8 @@
590590
;; no, create sub-alist from scratch
591591
(let ((pair (list txn-comm (cons (gnc:make-value-collector)
592592
(gnc:make-value-collector)))))
593-
((caadr pair) 'add value-amt)
594-
((cdadr pair) 'add share-amt)
593+
((caadr pair) 'add (- value-amt))
594+
((cdadr pair) 'add (- share-amt))
595595
;; and add the new sub-alist to sumlist.
596596
(loop (cdr comm-splits)
597597
(cons (list acc-comm (list pair)) sumlist)))))))))))

0 commit comments

Comments
 (0)