mpeg2: fix memory leak of empty packets.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Tue, 9 Oct 2012 13:40:49 +0000 (15:40 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Tue, 9 Oct 2012 16:05:48 +0000 (18:05 +0200)
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

index 2b8851f..92ff032 100644 (file)
@@ -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);