gst: Handle floating references consistently
authorSebastian Dröge <sebastian@centricular.com>
Mon, 15 May 2017 11:29:05 +0000 (14:29 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 17 May 2017 07:40:37 +0000 (10:40 +0300)
If a function takes a floating reference parameter, it should also be
sinked in error cases. Otherwise the function behaves differently
between error and normal cases, which is impossible for bindings to
handle.

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

gst/gstbin.c
gst/gstelement.c
gst/gstghostpad.c
gst/gstregistry.c
gst/gstutils.c

index 688988f..e1389cd 100644 (file)
@@ -1367,6 +1367,8 @@ adding_itself:
     GST_OBJECT_LOCK (bin);
     g_warning ("Cannot add bin '%s' to itself", GST_ELEMENT_NAME (bin));
     GST_OBJECT_UNLOCK (bin);
+    gst_object_ref_sink (element);
+    gst_object_unref (element);
     return FALSE;
   }
 duplicate_name:
@@ -1384,8 +1386,6 @@ had_parent:
     g_warning ("Element '%s' already has parent", elem_name);
     GST_OBJECT_UNLOCK (bin);
     g_free (elem_name);
-    gst_object_ref_sink (element);
-    gst_object_unref (element);
     return FALSE;
   }
 }
index 94efcb4..e4f68da 100644 (file)
@@ -734,8 +734,6 @@ had_parent:
         pad_name, GST_ELEMENT_NAME (element));
     GST_OBJECT_UNLOCK (element);
     g_free (pad_name);
-    gst_object_ref_sink (pad);
-    gst_object_unref (pad);
     return FALSE;
   }
 no_direction:
@@ -1275,6 +1273,7 @@ gst_element_class_add_pad_template (GstElementClass * klass,
 
     /* Found pad with the same name, replace and return */
     if (strcmp (templ->name_template, padtempl->name_template) == 0) {
+      gst_object_ref_sink (padtempl);
       gst_object_unref (padtempl);
       template_list->data = templ;
       return;
index b03ae7d..cd96668 100644 (file)
@@ -615,7 +615,6 @@ parent_failed:
     g_critical ("Could not set internal pad %s:%s",
         GST_DEBUG_PAD_NAME (internal));
     GST_OBJECT_UNLOCK (pad);
-    gst_object_unref (internal);
     return FALSE;
   }
 }
index dbd373a..198ca5f 100644 (file)
@@ -444,6 +444,8 @@ gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
         GST_WARNING_OBJECT (registry,
             "Not replacing plugin because new one (%s) is blacklisted but for a different location than existing one (%s)",
             plugin->filename, existing_plugin->filename);
+        /* Keep reference counting consistent */
+        gst_object_ref_sink (plugin);
         gst_object_unref (plugin);
         GST_OBJECT_UNLOCK (registry);
         return FALSE;
index ec3a335..94fb513 100644 (file)
@@ -1475,7 +1475,6 @@ ghost_up (GstElement * e, GstPad * pad)
   if (!gst_element_add_pad ((GstElement *) parent, gpad)) {
     g_warning ("Pad named %s already exists in element %s\n",
         GST_OBJECT_NAME (gpad), GST_OBJECT_NAME (parent));
-    gst_object_unref ((GstObject *) gpad);
     GST_STATE_UNLOCK (parent);
     return NULL;
   }
@@ -2059,7 +2058,6 @@ gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
 
     if (!gst_bin_add (GST_BIN (parent), capsfilter)) {
       GST_ERROR ("Could not add capsfilter");
-      gst_object_unref (capsfilter);
       gst_object_unref (parent);
       return FALSE;
     }