[gtk+] flowbox: Sink the floating reference of model-based children



commit 3de1bd383afddd3b530b612f8539d1866388b88d
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Aug 17 13:32:35 2015 +0100

    flowbox: Sink the floating reference of model-based children
    
    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 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c
index 40d60a2..e84b359 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);
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]