From 8766a6fab2143fcf0191872ca711dc046d10b7d7 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 26 Apr 2023 23:30:37 +0200 Subject: [PATCH] treelistmodel: Be safer during collapsing While we are collapsing a subtree, some signal handlers may not be disconnected while we are doing this. By adding this check and not giving those nodes no longer access to the model, we can stop it from modifying it while we are trying to collapse stuff. Fixes some crashes in gnome-builder. --- gtk/gtktreelistmodel.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gtk/gtktreelistmodel.c b/gtk/gtktreelistmodel.c index 1e55323c0a..81b4319c15 100644 --- a/gtk/gtktreelistmodel.c +++ b/gtk/gtktreelistmodel.c @@ -101,8 +101,15 @@ static GParamSpec *properties[NUM_PROPERTIES] = { NULL, }; static GtkTreeListModel * tree_node_get_tree_list_model (TreeNode *node) { - for (; !node->is_root; node = node->parent) - { } + if (node->is_root) + return node->list; + + for (node = node->parent; !node->is_root; node = node->parent) + { + /* This can happen during collapsing of a parent node */ + if (node->children == NULL) + return NULL; + } return node->list; } @@ -316,6 +323,9 @@ gtk_tree_list_model_items_changed_cb (GListModel *model, guint i, tree_position, tree_removed, tree_added, n_local; self = tree_node_get_tree_list_model (node); + if (self == NULL) + return; + n_local = g_list_model_get_n_items (model) - added + removed; if (position < n_local) @@ -1180,6 +1190,8 @@ gtk_tree_list_row_set_expanded (GtkTreeListRow *self, return; list = tree_node_get_tree_list_model (self->node); + if (list == NULL) + return; if (expanded) { @@ -1255,6 +1267,9 @@ gtk_tree_list_row_is_expandable (GtkTreeListRow *self) return TRUE; list = tree_node_get_tree_list_model (self->node); + if (list == NULL) + return FALSE; + model = tree_node_create_model (list, self->node); if (model) { -- 2.30.2