element: Enforce that elements created by gst_element_factory_create/make() are floating
[platform/upstream/gstreamer.git] / gst / gsttoc.c
index be99cb1..fd6bd66 100644 (file)
@@ -21,6 +21,7 @@
 
 /**
  * SECTION:gsttoc
+ * @title: GstToc
  * @short_description: Generic table of contents support
  * @see_also: #GstStructure, #GstEvent, #GstMessage, #GstQuery
  *
@@ -308,6 +309,10 @@ gst_toc_free (GstToc * toc)
   if (toc->tags != NULL)
     gst_tag_list_unref (toc->tags);
 
+#ifdef USE_POISONING
+  memset (toc, 0xff, sizeof (GstToc));
+#endif
+
   g_slice_free (GstToc, toc);
 }
 
@@ -324,6 +329,10 @@ gst_toc_entry_free (GstTocEntry * entry)
   if (entry->tags != NULL)
     gst_tag_list_unref (entry->tags);
 
+#ifdef USE_POISONING
+  memset (entry, 0xff, sizeof (GstTocEntry));
+#endif
+
   g_slice_free (GstTocEntry, entry);
 }
 
@@ -388,6 +397,18 @@ gst_toc_find_entry (const GstToc * toc, const gchar * uid)
   return NULL;
 }
 
+static GList *
+gst_toc_deep_copy_toc_entries (GList * entry_list)
+{
+  GQueue new_entries = G_QUEUE_INIT;
+  GList *l;
+
+  for (l = entry_list; l != NULL; l = l->next)
+    g_queue_push_tail (&new_entries, gst_toc_entry_copy (l->data));
+
+  return new_entries.head;
+}
+
 /**
  * gst_toc_entry_copy:
  * @entry: #GstTocEntry to copy.
@@ -401,9 +422,8 @@ gst_toc_find_entry (const GstToc * toc, const gchar * uid)
 static GstTocEntry *
 gst_toc_entry_copy (const GstTocEntry * entry)
 {
-  GstTocEntry *ret, *sub;
+  GstTocEntry *ret;
   GstTagList *list;
-  GList *cur;
 
   g_return_val_if_fail (entry != NULL, NULL);
 
@@ -419,16 +439,7 @@ gst_toc_entry_copy (const GstTocEntry * entry)
     ret->tags = list;
   }
 
-  cur = entry->subentries;
-  while (cur != NULL) {
-    sub = gst_toc_entry_copy (cur->data);
-
-    if (sub != NULL)
-      ret->subentries = g_list_prepend (ret->subentries, sub);
-
-    cur = cur->next;
-  }
-  ret->subentries = g_list_reverse (ret->subentries);
+  ret->subentries = gst_toc_deep_copy_toc_entries (entry->subentries);
 
   return ret;
 }
@@ -446,8 +457,6 @@ static GstToc *
 gst_toc_copy (const GstToc * toc)
 {
   GstToc *ret;
-  GstTocEntry *entry;
-  GList *cur;
   GstTagList *list;
 
   g_return_val_if_fail (toc != NULL, NULL);
@@ -460,16 +469,8 @@ gst_toc_copy (const GstToc * toc)
     ret->tags = list;
   }
 
-  cur = toc->entries;
-  while (cur != NULL) {
-    entry = gst_toc_entry_copy (cur->data);
-
-    if (entry != NULL)
-      ret->entries = g_list_prepend (ret->entries, entry);
+  ret->entries = gst_toc_deep_copy_toc_entries (toc->entries);
 
-    cur = cur->next;
-  }
-  ret->entries = g_list_reverse (ret->entries);
   return ret;
 }
 
@@ -784,7 +785,7 @@ gst_toc_entry_get_toc (GstTocEntry * entry)
  *
  * Gets the parent #GstTocEntry of @entry.
  *
- * Returns: (transfer none): The parent #GstTocEntry of @entry
+ * Returns: (transfer none) (nullable): The parent #GstTocEntry of @entry
  */
 GstTocEntry *
 gst_toc_entry_get_parent (GstTocEntry * entry)