diff options
author | Debarshi Ray <debarshir@gnome.org> | 2015-03-01 13:28:21 +0100 |
---|---|---|
committer | Debarshi Ray <debarshir@gnome.org> | 2015-03-02 11:53:52 +0100 |
commit | 7c4bf742e82d812ecc5b0c3280db86d2689eb093 (patch) | |
tree | ccd673f8fff454960cb980422d9be4f25b0fb568 /gtk/gtkeventcontroller.c | |
parent | 66d25c4a060458001d4725aceb39a0a1a12db39a (diff) | |
download | gtk+-7c4bf742e82d812ecc5b0c3280db86d2689eb093.tar.gz |
eventcontroller, widget: Don't crash if destroyed before the other
There are two scenarios. A widget sub-class owns a GtkEventController
and passes itself to it, or a controller owned by something else is
passed a widget.
In the second case, if the widget is destroyed before the controller,
we will have a crash when destructing the controller because we will
be accessing invalid memory. Adding a weak reference on the widget
addresses that problem.
This leads to a crash in the first case. When the widget is getting
destroyed, it will drop the reference to its own controller. The
controller will skip touching the widget because the weak reference
would have turned it to NULL. However, when the widget sub-class chains
up to GtkWidget it will try to free all the controllers in its list.
Unfortunately, all these controllers have already been destroyed. So
we need to guard against this too.
https://bugzilla.gnome.org/show_bug.cgi?id=745225
Diffstat (limited to 'gtk/gtkeventcontroller.c')
-rw-r--r-- | gtk/gtkeventcontroller.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/gtk/gtkeventcontroller.c b/gtk/gtkeventcontroller.c index 4a77040bdd..c20c84e0d3 100644 --- a/gtk/gtkeventcontroller.c +++ b/gtk/gtkeventcontroller.c @@ -75,6 +75,7 @@ gtk_event_controller_set_property (GObject *object, { case PROP_WIDGET: priv->widget = g_value_get_object (value); + g_object_add_weak_pointer (G_OBJECT (priv->widget), (gpointer *) &priv->widget); break; case PROP_PROPAGATION_PHASE: gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (object), |