From 2e4c82d850981ac65b55a95922fda5f861bbbc57 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 15 May 2017 14:29:05 +0300 Subject: [PATCH] gst: Handle floating references consistently 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 | 4 ++-- gst/gstelement.c | 3 +-- gst/gstghostpad.c | 1 - gst/gstregistry.c | 2 ++ gst/gstutils.c | 2 -- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/gst/gstbin.c b/gst/gstbin.c index 688988f..e1389cd 100644 --- a/gst/gstbin.c +++ b/gst/gstbin.c @@ -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; } } diff --git a/gst/gstelement.c b/gst/gstelement.c index 94efcb4..e4f68da 100644 --- a/gst/gstelement.c +++ b/gst/gstelement.c @@ -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; diff --git a/gst/gstghostpad.c b/gst/gstghostpad.c index b03ae7d..cd96668 100644 --- a/gst/gstghostpad.c +++ b/gst/gstghostpad.c @@ -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; } } diff --git a/gst/gstregistry.c b/gst/gstregistry.c index dbd373a..198ca5f 100644 --- a/gst/gstregistry.c +++ b/gst/gstregistry.c @@ -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; diff --git a/gst/gstutils.c b/gst/gstutils.c index ec3a335..94fb513 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -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; } -- 2.7.4