timeline: fix paste ownership
authorHenry Wilkes <hwilkes@igalia.com>
Fri, 20 Dec 2019 11:20:49 +0000 (11:20 +0000)
committerThibault Saunier <tsaunier@igalia.com>
Thu, 5 Mar 2020 19:59:37 +0000 (16:59 -0300)
The method steals ownership of `copied_from`, so should be responsible
for unreffing it. Also make sure we fail when `layer != -1`, since this
functionality is not supported.

ges/ges-timeline.c

index 569f640..6693878 100644 (file)
@@ -2779,6 +2779,7 @@ ges_timeline_paste_element (GESTimeline * timeline,
   CHECK_THREAD (timeline);
 
   element_class = GES_TIMELINE_ELEMENT_GET_CLASS (element);
+  /* steal ownership of the copied element */
   copied_from = ges_timeline_element_get_copied_from (element);
 
   if (!copied_from) {
@@ -2789,7 +2790,7 @@ ges_timeline_paste_element (GESTimeline * timeline,
 
   if (!element_class->paste) {
     GST_ERROR_OBJECT (element, "No paste vmethod implemented");
-
+    gst_object_unref (copied_from);
     return NULL;
   }
 
@@ -2800,13 +2801,15 @@ ges_timeline_paste_element (GESTimeline * timeline,
   if (layer_priority != -1) {
     GST_WARNING_OBJECT (timeline,
         "Only -1 value for layer priority is supported");
+    gst_object_unref (copied_from);
+    return NULL;
   }
 
   res = element_class->paste (element, copied_from, position);
 
-  g_clear_object (&copied_from);
+  gst_object_unref (copied_from);
 
-  return g_object_ref (res);
+  return res ? g_object_ref (res) : res;
 }
 
 /**