From 91da4fcb18dc83e8e03caf8905a5ee09c564444b Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Tue, 9 Oct 2012 15:40:49 +0200 Subject: [PATCH] mpeg2: fix memory leak of empty packets. Fix memory leakage of empty packets, i.e. packets that only contain the start code prefix. In particular, free empty user-data packets. Besides, the codec parser will already fail gracefully if the packet to parse does not have the minimum required size. So, we can also completely drop the block of code that used to handle packets of size 4 (including the start code). --- gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c b/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c index 2b8851f..92ff032 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c @@ -971,7 +971,7 @@ decode_buffer(GstVaapiDecoderMpeg2 *decoder, GstBuffer *buffer) } status = GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA; - if (size < 8) + if (size < 4) break; ofs = scan_for_start_code(priv->adapter, 0, size, &start_code); if (ofs < 0) @@ -992,17 +992,6 @@ decode_buffer(GstVaapiDecoderMpeg2 *decoder, GstBuffer *buffer) buffer = gst_adapter_take_buffer(priv->adapter, ofs); size -= ofs; - if (ofs == 4) { - // Ignore empty user-data packets - if ((start_code & 0xff) == GST_MPEG_VIDEO_PACKET_USER_DATA) { - status = GST_VAAPI_DECODER_STATUS_SUCCESS; - continue; - } - GST_ERROR("failed to get a valid packet (SC: 0x%08x)", start_code); - status = GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER; - break; - } - buf = GST_BUFFER_DATA(buffer); buf_size = GST_BUFFER_SIZE(buffer); -- 2.7.4