From 673d13f1760c93924c71fce8b6b14debccf7e533 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Thu, 13 Oct 2022 22:15:58 +0530 Subject: [PATCH] playbin3: Fix missing pad unref 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: --- .../gst-plugins-base/gst/playback/gstplaybin3.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-base/gst/playback/gstplaybin3.c b/subprojects/gst-plugins-base/gst/playback/gstplaybin3.c index 1072705875..ba8a4ecd4f 100644 --- a/subprojects/gst-plugins-base/gst/playback/gstplaybin3.c +++ b/subprojects/gst-plugins-base/gst/playback/gstplaybin3.c @@ -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);