Skip to content

Commit 66a8ebc

Browse files
committed
extension-row: Fix crash caused by reference cycle
1 parent 725a8d2 commit 66a8ebc

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

src/exm-extension-row.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ static void
4343
bind_extension (ExmExtensionRow *self,
4444
ExmExtension *extension);
4545

46+
static void
47+
unbind_extension (ExmExtensionRow *self);
48+
4649
ExmExtensionRow *
4750
exm_extension_row_new (ExmExtension *extension)
4851
{
@@ -59,6 +62,16 @@ exm_extension_row_finalize (GObject *object)
5962
G_OBJECT_CLASS (exm_extension_row_parent_class)->finalize (object);
6063
}
6164

65+
static void
66+
exm_extension_row_dispose (GObject *object)
67+
{
68+
ExmExtensionRow *self = (ExmExtensionRow *)object;
69+
70+
unbind_extension (self);
71+
72+
G_OBJECT_CLASS (exm_extension_row_parent_class)->dispose (object);
73+
}
74+
6275
static void
6376
exm_extension_row_get_property (GObject *object,
6477
guint prop_id,
@@ -105,6 +118,11 @@ update_state (ExmExtension *extension,
105118
// the extension. We do not want this behaviour as it messes with the global
106119
// extension toggle.
107120

121+
g_return_if_fail (EXM_IS_EXTENSION (extension));
122+
g_return_if_fail (EXM_IS_EXTENSION_ROW (row));
123+
124+
g_assert (row->extension == extension);
125+
108126
const gchar *uuid;
109127
ExmExtensionState new_state;
110128
GAction *action;
@@ -166,6 +184,17 @@ set_error_label_visible (ExmExtensionRow *self,
166184
gtk_widget_set_visible (GTK_WIDGET (self->error_label_tag), visible);
167185
}
168186

187+
static void
188+
unbind_extension (ExmExtensionRow *self)
189+
{
190+
if (self->extension != NULL)
191+
{
192+
g_signal_handler_disconnect (self->extension, self->signal_handler);
193+
g_clear_object (&self->extension);
194+
g_clear_pointer (&self->uuid, g_free);
195+
}
196+
}
197+
169198
static void
170199
bind_extension (ExmExtensionRow *self,
171200
ExmExtension *extension)
@@ -178,15 +207,10 @@ bind_extension (ExmExtensionRow *self,
178207
g_return_if_fail (EXM_IS_EXTENSION_ROW (self));
179208

180209
// First, remove traces of the old extension
181-
if (self->extension != NULL)
182-
{
183-
g_signal_handler_disconnect (self->extension, self->signal_handler);
184-
g_clear_object (&self->extension);
185-
g_clear_pointer (&self->uuid, g_free);
186-
}
210+
unbind_extension (self);
187211

188212
// Now, bind the new one
189-
self->extension = extension;
213+
self->extension = g_object_ref (extension);
190214

191215
if (self->extension == NULL)
192216
return;
@@ -252,6 +276,7 @@ exm_extension_row_class_init (ExmExtensionRowClass *klass)
252276
GObjectClass *object_class = G_OBJECT_CLASS (klass);
253277

254278
object_class->finalize = exm_extension_row_finalize;
279+
object_class->dispose = exm_extension_row_dispose;
255280
object_class->get_property = exm_extension_row_get_property;
256281
object_class->set_property = exm_extension_row_set_property;
257282

src/exm-installed-page.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ bind_list_box (GtkListBox *list_box,
165165
gboolean sort_enabled_first)
166166
{
167167
GtkExpression *expression;
168-
GtkCustomSorter *enabled_sorter;
169168
GtkStringSorter *alphabetical_sorter;
170-
GtkMultiSorter *multi_sorter;
171169
GtkSortListModel *sorted_model;
172170

173171
// Sort alphabetically
@@ -176,6 +174,9 @@ bind_list_box (GtkListBox *list_box,
176174

177175
if (sort_enabled_first)
178176
{
177+
GtkCustomSorter *enabled_sorter;
178+
GtkMultiSorter *multi_sorter;
179+
179180
// Sort by enabled
180181
enabled_sorter = gtk_custom_sorter_new ((GCompareDataFunc) compare_enabled, NULL, NULL);
181182

0 commit comments

Comments
 (0)