element: Enforce that elements created by gst_element_factory_create/make() are floating
[platform/upstream/gstreamer.git] / gst / gstdevice.c
index 786acfb..64f5ba5 100644 (file)
@@ -196,7 +196,7 @@ gst_device_set_property (GObject * object, guint prop_id,
  * Creates the element with all of the required parameters set to use
  * this device.
  *
- * Returns: (transfer full) (nullable): a new #GstElement configured to use
+ * Returns: (transfer floating) (nullable): a new #GstElement configured to use
  * this device
  *
  * Since: 1.4
@@ -205,13 +205,20 @@ GstElement *
 gst_device_create_element (GstDevice * device, const gchar * name)
 {
   GstDeviceClass *klass = GST_DEVICE_GET_CLASS (device);
+  GstElement *element = NULL;
 
   g_return_val_if_fail (GST_IS_DEVICE (device), NULL);
 
   if (klass->create_element)
-    return klass->create_element (device, name);
-  else
-    return NULL;
+    element = klass->create_element (device, name);
+
+  /* Ensure that the reference is floating. Bindings might have a hard time
+   * making sure that the reference is indeed still floating after returning
+   * here */
+  if (element)
+    g_object_force_floating ((GObject *) element);
+
+  return element;
 }
 
 /**