bin: When copying the sort iterator, also copy its internal queue
authorKouhei Sutou <kou@clear-code.com>
Mon, 19 Sep 2016 14:04:55 +0000 (10:04 -0400)
committerSebastian Dröge <sebastian@centricular.com>
Mon, 19 Sep 2016 14:04:55 +0000 (10:04 -0400)
Otherwise both iterators share the same references, the second one
usually resulting in a crash when being freed.

https://bugzilla.gnome.org/show_bug.cgi?id=771649

gst/gstbin.c

index a76810e..28bae67 100644 (file)
@@ -2135,14 +2135,24 @@ typedef struct _GstBinSortIterator
 } GstBinSortIterator;
 
 static void
+copy_to_queue (gpointer data, gpointer user_data)
+{
+  GstElement *element = data;
+  GQueue *queue = user_data;
+
+  gst_object_ref (element);
+  g_queue_push_tail (queue, element);
+}
+
+static void
 gst_bin_sort_iterator_copy (const GstBinSortIterator * it,
     GstBinSortIterator * copy)
 {
   GHashTableIter iter;
   gpointer key, value;
 
-  copy->queue = it->queue;
-  g_queue_foreach (&copy->queue, (GFunc) gst_object_ref, NULL);
+  g_queue_init (&copy->queue);
+  g_queue_foreach (&it->queue, copy_to_queue, &copy->queue);
 
   copy->bin = gst_object_ref (it->bin);
   if (it->best)