From 3de1bd383afddd3b530b612f8539d1866388b88d Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 17 Aug 2015 13:32:35 +0100 Subject: [PATCH] flowbox: Sink the floating reference of model-based children MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don't want to leak references if the widget created to represent the item in the model does not have a floating reference — which is usually what happens in bindings, as they automatically sink references when creating new instances. See commit 6e03e7e8 for the similar change in GtkListBox. --- gtk/gtkflowbox.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c index 40d60a240a..e84b3597a9 100644 --- a/gtk/gtkflowbox.c +++ b/gtk/gtkflowbox.c @@ -4036,9 +4036,22 @@ gtk_flow_box_bound_model_changed (GListModel *list, item = g_list_model_get_item (list, position + i); widget = priv->create_widget_func (item, priv->create_widget_func_data); + + /* We need to sink the floating reference here, so that we can accept + * both instances created with a floating reference (e.g. C functions + * that just return the result of g_object_new()) and without (e.g. + * from language bindings which will automatically sink the floating + * reference). + * + * See the similar code in gtklistbox.c:gtk_list_box_bound_model_changed. + */ + if (g_object_is_floating (widget)) + g_object_ref_sink (widget); + gtk_widget_show (widget); gtk_flow_box_insert (box, widget, position + i); + g_object_unref (widget); g_object_unref (item); } }