uridecodebin: use non-floating object as signal argument
authorMark Nauwelaerts <mnauw@users.sourceforge.net>
Thu, 16 Dec 2021 15:43:37 +0000 (16:43 +0100)
committerMark Nauwelaerts <mnauw@users.sourceforge.net>
Sun, 19 Dec 2021 17:27:50 +0000 (18:27 +0100)
... as was the case with source-setup signal until change of order
in commit 52bca104e447309898ca8904b3914211ec7d4114

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1457>

subprojects/gst-plugins-base/gst/playback/gsturidecodebin.c

index e66f8f7..1f4250f 100644 (file)
@@ -1321,6 +1321,8 @@ static const gchar *adaptive_media[] = {
 
 /*
  * Generate and configure a source element.
+ *
+ * Returns: (transfer full): a new #GstElement
  */
 static GstElement *
 gen_source_element (GstURIDecodeBin * decoder)
@@ -1397,6 +1399,15 @@ gen_source_element (GstURIDecodeBin * decoder)
     g_object_set (source, "subtitle-encoding", decoder->encoding, NULL);
   }
 
+  /* Sink reference before passing it to signal handler.
+   * Language binding might otherwise sink it and then unref.
+   * A floating ref is also tricky for a native signal handler in case
+   * of a "transfer floating" call followed by unref
+   * (e.g. some container_add and then container_remove).
+   * Bottom line; best not have a floating ref boldly going into unknown code.
+   */
+  g_object_ref_sink (source);
+
   g_signal_emit (decoder, gst_uri_decode_bin_signals[SIGNAL_SOURCE_SETUP],
       0, source);
 
@@ -2262,6 +2273,8 @@ setup_source (GstURIDecodeBin * decoder)
   /* state will be merged later - if file is not found, error will be
    * handled by the application right after. */
   gst_bin_add (GST_BIN_CAST (decoder), decoder->source);
+  /* bin now has a ref, but the local reference is not counted */
+  g_object_unref (decoder->source);
 
   /* notify of the new source used */
   g_object_notify (G_OBJECT (decoder), "source");