widget: Free the controller list on finalize()

If this is done on dispose(), the widget may be destroyed (and its
controllers list NULLified) within _gtk_widget_run_controllers(),
causing warnings/crashes when it just tried to hop on the next
controllers.

Freeing the controllers here should be a safety net for implementations,
so it also makes sense to do this late. The widgets that choose to
free their controllers on dispose can still do so, and get
_gtk_widget_remove_controller() called for these as an indirect result.
This commit is contained in:
Carlos Garnacho 2015-01-14 16:59:36 +01:00
parent 594de00cad
commit b8e87d4762

View File

@ -11924,7 +11924,6 @@ gtk_widget_dispose (GObject *object)
{
GtkWidget *widget = GTK_WIDGET (object);
GtkWidgetPrivate *priv = widget->priv;
GList *l;
if (priv->parent)
gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
@ -11947,15 +11946,6 @@ gtk_widget_dispose (GObject *object)
while (priv->attached_windows)
gtk_window_set_attached_to (priv->attached_windows->data, NULL);
for (l = priv->event_controllers; l; l = l->next)
{
EventControllerData *data = l->data;
if (data->controller)
_gtk_widget_remove_controller (widget, data->controller);
}
g_list_free_full (priv->event_controllers, g_free);
priv->event_controllers = NULL;
G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
}
@ -12150,6 +12140,7 @@ gtk_widget_finalize (GObject *object)
GtkWidgetPrivate *priv = widget->priv;
GtkWidgetAuxInfo *aux_info;
GtkAccessible *accessible;
GList *l;
gtk_grab_remove (widget);
@ -12176,6 +12167,15 @@ gtk_widget_finalize (GObject *object)
_gtk_size_request_cache_free (&priv->requests);
for (l = priv->event_controllers; l; l = l->next)
{
EventControllerData *data = l->data;
if (data->controller)
_gtk_widget_remove_controller (widget, data->controller);
}
g_list_free_full (priv->event_controllers, g_free);
priv->event_controllers = NULL;
if (g_object_is_floating (object))
g_warning ("A floating object was finalized. This means that someone\n"
"called g_object_unref() on an object that had only a floating\n"