mpegtsdemux: Close a buffer leak and simplify input_done
authorJan Alexander Steffens (heftig) <jan.steffens@ltnglobal.com>
Fri, 15 May 2020 15:05:59 +0000 (17:05 +0200)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 18 May 2020 14:11:40 +0000 (14:11 +0000)
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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1274>

gst/mpegtsdemux/mpegtsbase.c
gst/mpegtsdemux/mpegtsbase.h
gst/mpegtsdemux/mpegtsparse.c

index 3ca041c..237a893 100644 (file)
@@ -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;
 }
index 261653c..14dce2f 100644 (file)
@@ -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);
index c5ee140..bcf6727 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * mpegtsparse.c - 
+ * mpegtsparse.c -
  * Copyright (C) 2007 Alessandro Decina
- * 
+ *
  * Authors:
  *   Alessandro Decina <alessandro@nnva.org>
  *   Zaheer Abbas Merali <zaheerabbas at merali dot org>
@@ -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;