From 9b2ed3a3fc5717362918e460d26b61052f8eef76 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Fri, 15 May 2020 17:05:59 +0200 Subject: [PATCH] mpegtsdemux: Close a buffer leak and simplify input_done tsparse leaked input buffers quite badly: GST_TRACERS=leaks GST_DEBUG=GST_TRACER:9 gst-launch-1.0 audiotestsrc num-buffers=3 ! avenc_aac ! mpegtsmux ! tsparse ! fakesink The input_done vfunc was passed the input buffer, which it had to consume. For this reason, the base class takes a reference on the buffer if and only if input_done is not NULL. Before 34af8ed66a7c63048ce0bdf59bbe61011d7c6292, input_done was used in tsparse to pass on the input buffer on the "src" pad. That commit changed the code to packetize for that pad as well and removed the use of input_done. Afterwards, 0d2e9085236ed94622c327f73489e558cc95d05f set input_done again in order to handle automatic alignment of the output buffers to the input buffers. However, it ignored the provided buffer and did not even unref it, causing a leak. Since no code makes use of the buffer provided with input_done, just remove the argument in order to simplify things a bit. Part-of: --- gst/mpegtsdemux/mpegtsbase.c | 11 ++--------- gst/mpegtsdemux/mpegtsbase.h | 2 +- gst/mpegtsdemux/mpegtsparse.c | 9 ++++----- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/gst/mpegtsdemux/mpegtsbase.c b/gst/mpegtsdemux/mpegtsbase.c index 3ca041c7e2..237a8938b7 100644 --- a/gst/mpegtsdemux/mpegtsbase.c +++ b/gst/mpegtsdemux/mpegtsbase.c @@ -1431,9 +1431,6 @@ mpegts_base_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) packetizer = base->packetizer; - if (klass->input_done) - gst_buffer_ref (buf); - if (GST_BUFFER_IS_DISCONT (buf)) { GST_DEBUG_OBJECT (base, "Got DISCONT buffer, flushing"); res = mpegts_base_drain (base); @@ -1501,12 +1498,8 @@ mpegts_base_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) mpegts_packetizer_clear_packet (base->packetizer, &packet); } - if (klass->input_done) { - if (res == GST_FLOW_OK) - res = klass->input_done (base, buf); - else - gst_buffer_unref (buf); - } + if (res == GST_FLOW_OK && klass->input_done) + res = klass->input_done (base); return res; } diff --git a/gst/mpegtsdemux/mpegtsbase.h b/gst/mpegtsdemux/mpegtsbase.h index 261653cb1f..14dce2fbf2 100644 --- a/gst/mpegtsdemux/mpegtsbase.h +++ b/gst/mpegtsdemux/mpegtsbase.h @@ -210,7 +210,7 @@ struct _MpegTSBaseClass { void (*flush) (MpegTSBase * base, gboolean hard); /* Notifies subclasses input buffer has been handled */ - GstFlowReturn (*input_done) (MpegTSBase *base, GstBuffer *buffer); + GstFlowReturn (*input_done) (MpegTSBase *base); /* signals */ void (*pat_info) (GstStructure *pat); diff --git a/gst/mpegtsdemux/mpegtsparse.c b/gst/mpegtsdemux/mpegtsparse.c index c5ee140ac5..bcf67275bd 100644 --- a/gst/mpegtsdemux/mpegtsparse.c +++ b/gst/mpegtsdemux/mpegtsparse.c @@ -1,7 +1,7 @@ /* - * mpegtsparse.c - + * mpegtsparse.c - * Copyright (C) 2007 Alessandro Decina - * + * * Authors: * Alessandro Decina * Zaheer Abbas Merali @@ -126,8 +126,7 @@ static gboolean push_event (MpegTSBase * base, GstEvent * event); #define mpegts_parse_parent_class parent_class G_DEFINE_TYPE (MpegTSParse2, mpegts_parse, GST_TYPE_MPEGTS_BASE); static void mpegts_parse_reset (MpegTSBase * base); -static GstFlowReturn mpegts_parse_input_done (MpegTSBase * base, - GstBuffer * buffer); +static GstFlowReturn mpegts_parse_input_done (MpegTSBase * base); static GstFlowReturn drain_pending_buffers (MpegTSParse2 * parse, gboolean drain_all); @@ -1088,7 +1087,7 @@ empty_pad (GstPad * pad, MpegTSParse2 * parse) } static GstFlowReturn -mpegts_parse_input_done (MpegTSBase * base, GstBuffer * buffer) +mpegts_parse_input_done (MpegTSBase * base) { MpegTSParse2 *parse = GST_MPEGTS_PARSE (base); GstFlowReturn ret = GST_FLOW_OK;