playbin3: Fix missing pad unref
authorSanchayan Maity <sanchayan@asymptotic.io>
Thu, 13 Oct 2022 16:45:58 +0000 (22:15 +0530)
committerSanchayan Maity <sanchayan@asymptotic.io>
Fri, 28 Oct 2022 04:45:42 +0000 (10:15 +0530)
GST_TRACERS="leaks" GST_DEBUG="GST_TRACER:7,leaks:6" gst-play-1.0 --use-playbin3 test.mkv

When running a pipeline like above, leaks are observed.

0:00:56.882419132 240637 0x5562c528ccc0 TRACE             GST_TRACER :0:: object-alive, type-name=(string)GstConcatPad, address=(gpointer)0x7efd7c0d20a0, description=(string)<'':sink_0>, ref-count=(uint)1, trace=(string);
0:00:56.882429131 240637 0x5562c528ccc0 TRACE             GST_TRACER :0:: object-alive, type-name=(string)GstConcatPad, address=(gpointer)0x7efd7c0d2be0, description=(string)<'':sink_0>, ref-count=(uint)1, trace=(string);
0:00:56.882437056 240637 0x5562c528ccc0 TRACE             GST_TRACER :0:: object-alive, type-name=(string)GstConcatPad, address=(gpointer)0x7efd7c0d3720, description=(string)<'':sink_0>, ref-count=(uint)1, trace=(string);

gst_element_release_request_pad does not unref the pad. It needs to
be followed by gst_object_unref. Doing that fixes the above leaks.

Use g_ptr_array_new_with_free_func with gst_object_unref as the free
function to unref the pad after release.

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

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

index 1072705..ba8a4ec 100644 (file)
@@ -1089,17 +1089,20 @@ static void
 init_combiners (GstPlayBin3 * playbin)
 {
   playbin->combiner[PLAYBIN_STREAM_AUDIO].stream_type = GST_STREAM_TYPE_AUDIO;
-  playbin->combiner[PLAYBIN_STREAM_AUDIO].inputpads = g_ptr_array_new ();
+  playbin->combiner[PLAYBIN_STREAM_AUDIO].inputpads =
+      g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
   playbin->combiner[PLAYBIN_STREAM_AUDIO].streams =
       g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
 
   playbin->combiner[PLAYBIN_STREAM_VIDEO].stream_type = GST_STREAM_TYPE_VIDEO;
-  playbin->combiner[PLAYBIN_STREAM_VIDEO].inputpads = g_ptr_array_new ();
+  playbin->combiner[PLAYBIN_STREAM_VIDEO].inputpads =
+      g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
   playbin->combiner[PLAYBIN_STREAM_VIDEO].streams =
       g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
 
   playbin->combiner[PLAYBIN_STREAM_TEXT].stream_type = GST_STREAM_TYPE_TEXT;
-  playbin->combiner[PLAYBIN_STREAM_TEXT].inputpads = g_ptr_array_new ();
+  playbin->combiner[PLAYBIN_STREAM_TEXT].inputpads =
+      g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
   playbin->combiner[PLAYBIN_STREAM_TEXT].streams =
       g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
 }
@@ -2832,7 +2835,6 @@ remove_combiner (GstPlayBin3 * playbin, GstSourceCombine * combine)
     GstPad *sinkpad = g_ptr_array_index (combine->inputpads, n);
 
     gst_element_release_request_pad (combine->combiner, sinkpad);
-    gst_object_unref (sinkpad);
   }
   g_ptr_array_set_size (combine->inputpads, 0);