From c499a81848fb0c75a5705be481abb46949cb624e Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Fri, 8 Feb 2013 01:02:10 +1100 Subject: [PATCH] avimux: Fixing buffer leak in gst_avi_mux_do_buffer gst_avi_mux_do_buffer was leaking data from gst_collect_pads_pop. --- gst/avi/gstavimux.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/gst/avi/gstavimux.c b/gst/avi/gstavimux.c index 5068600..6a9f3be 100644 --- a/gst/avi/gstavimux.c +++ b/gst/avi/gstavimux.c @@ -1932,6 +1932,7 @@ gst_avi_mux_do_buffer (GstAviMux * avimux, GstAviPad * avipad) GstAviVideoPad *vidpad = (GstAviVideoPad *) avipad; if (vidpad->prepend_buffer) { + /* Keep a reference to data until we copy the timestamps, then release it */ GstBuffer *newdata = gst_buffer_append (vidpad->prepend_buffer, gst_buffer_ref (data)); gst_buffer_copy_into (newdata, data, GST_BUFFER_COPY_TIMESTAMPS, 0, -1); @@ -1944,7 +1945,7 @@ gst_avi_mux_do_buffer (GstAviMux * avimux, GstAviPad * avipad) if (avimux->restart) { if ((res = gst_avi_mux_restart_file (avimux)) != GST_FLOW_OK) - return res; + goto done; } datasize = gst_buffer_get_size (data); @@ -1954,10 +1955,10 @@ gst_avi_mux_do_buffer (GstAviMux * avimux, GstAviPad * avipad) datasize > GST_AVI_MAX_SIZE) { if (avimux->enable_large_avi) { if ((res = gst_avi_mux_bigfile (avimux, FALSE)) != GST_FLOW_OK) - return res; + goto done; } else { if ((res = gst_avi_mux_restart_file (avimux)) != GST_FLOW_OK) - return res; + goto done; } } @@ -1974,8 +1975,10 @@ gst_avi_mux_do_buffer (GstAviMux * avimux, GstAviPad * avipad) avimux->data_size += total_size; } - if (G_UNLIKELY (avipad->hook)) + if (G_UNLIKELY (avipad->hook)) { + gst_buffer_ref (data); avipad->hook (avimux, avipad, data); + } /* the suggested buffer size is the max frame size */ if (avipad->hdr.bufsize < datasize) @@ -2007,19 +2010,23 @@ gst_avi_mux_do_buffer (GstAviMux * avimux, GstAviPad * avipad) GST_LOG_OBJECT (avimux, "pushing buffers: head, data"); if ((res = gst_pad_push (avimux->srcpad, header)) != GST_FLOW_OK) - return res; + goto done; + + gst_buffer_ref (data); if ((res = gst_pad_push (avimux->srcpad, data)) != GST_FLOW_OK) - return res; + goto done; if (pad_bytes) { if ((res = gst_avi_mux_send_pad_data (avimux, pad_bytes)) != GST_FLOW_OK) - return res; + goto done; } /* if any push above fails, we're in trouble with file consistency anyway */ avimux->total_data += total_size; avimux->idx_offset += total_size; +done: + gst_buffer_unref (data); return res; } -- 2.7.4