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
This commit is contained in:
Debarshi Ray
2015-03-01 13:28:21 +01:00
parent 6e5e282b59
commit 95ea70e2da
2 changed files with 3 additions and 0 deletions

View File

@@ -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),

View File

@@ -17104,6 +17104,8 @@ _gtk_widget_add_controller (GtkWidget *widget,
g_signal_connect (widget, "grab-notify",
G_CALLBACK (event_controller_grab_notify), data);
g_object_add_weak_pointer (G_OBJECT (data->controller), (gpointer *) &data->controller);
if (GTK_IS_GESTURE (controller))
{
data->sequence_state_changed_id =