qtdemux: fix buffer leak on eos in push mode
authorTim-Philipp Müller <tim@centricular.com>
Thu, 30 Apr 2015 11:13:59 +0000 (12:13 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 30 Apr 2015 12:35:16 +0000 (13:35 +0100)
Based on patch by Guillaume Desmottes.

scenario: validate.http.playback.seek_with_stop.raw_h264_1_mp4

https://bugzilla.gnome.org/show_bug.cgi?id=748617

gst/isomp4/qtdemux.c

index 80f7ae3..bc8a500 100644 (file)
@@ -5345,7 +5345,6 @@ gst_qtdemux_process_adapter (GstQTDemux * demux, gboolean force)
         break;
       }
       case QTDEMUX_STATE_MOVIE:{
-        GstBuffer *outbuf;
         QtDemuxStream *stream = NULL;
         QtDemuxSample *sample;
         int i = -1;
@@ -5440,12 +5439,9 @@ gst_qtdemux_process_adapter (GstQTDemux * demux, gboolean force)
         sample = &stream->samples[stream->sample_index];
 
         if (G_LIKELY (!(STREAM_IS_EOS (stream)))) {
-          outbuf = gst_adapter_take_buffer (demux->adapter, demux->neededbytes);
           GST_DEBUG_OBJECT (demux, "stream : %" GST_FOURCC_FORMAT,
               GST_FOURCC_ARGS (stream->fourcc));
 
-          g_return_val_if_fail (outbuf != NULL, GST_FLOW_ERROR);
-
           dts = QTSAMPLE_DTS (stream, sample);
           pts = QTSAMPLE_PTS (stream, sample);
           duration = QTSAMPLE_DUR_DTS (stream, sample, dts);
@@ -5457,6 +5453,9 @@ gst_qtdemux_process_adapter (GstQTDemux * demux, gboolean force)
             GST_DEBUG_OBJECT (demux, "we reached the end of our segment.");
             stream->time_position = GST_CLOCK_TIME_NONE;        /* this means EOS */
 
+            /* skip this data, stream is EOS */
+            gst_adapter_flush (demux->adapter, demux->neededbytes);
+
             /* check if all streams are eos */
             ret = GST_FLOW_EOS;
             for (i = 0; i < demux->n_streams; i++) {
@@ -5471,6 +5470,14 @@ gst_qtdemux_process_adapter (GstQTDemux * demux, gboolean force)
               goto eos;
             }
           } else {
+            GstBuffer *outbuf;
+
+            outbuf =
+                gst_adapter_take_buffer (demux->adapter, demux->neededbytes);
+
+            /* FIXME: should either be an assert or a plain check */
+            g_return_val_if_fail (outbuf != NULL, GST_FLOW_ERROR);
+
             ret = gst_qtdemux_decorate_and_push_buffer (demux, stream, outbuf,
                 dts, pts, duration, keyframe, dts, demux->offset);
           }