From 96b900028996c6cdb155d343aa02dd9cb9bfaa6d Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Thu, 23 Jul 2020 17:48:56 +0900 Subject: [PATCH] v4l2codecs: h264dec: Fix leak on decoding failure Given GstVideoCodecFrame and GstH264Picture should be cleared, and the return must be GST_FLOW_ERROR, not boolean value. Part-of: --- sys/v4l2codecs/gstv4l2codech264dec.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sys/v4l2codecs/gstv4l2codech264dec.c b/sys/v4l2codecs/gstv4l2codech264dec.c index 2994863610..55825a88f0 100644 --- a/sys/v4l2codecs/gstv4l2codech264dec.c +++ b/sys/v4l2codecs/gstv4l2codech264dec.c @@ -846,6 +846,7 @@ gst_v4l2_codec_h264_dec_output_picture (GstH264Decoder * decoder, GstVideoCodecFrame * frame, GstH264Picture * picture) { GstV4l2CodecH264Dec *self = GST_V4L2_CODEC_H264_DEC (decoder); + GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder); GstV4l2Request *request = gst_h264_picture_get_user_data (picture); guint32 frame_num; GstH264Picture *other_pic; @@ -857,15 +858,13 @@ gst_v4l2_codec_h264_dec_output_picture (GstH264Decoder * decoder, goto finish_frame; if (!gst_v4l2_codec_h264_dec_wait (self, request)) - return FALSE; + goto error; while (TRUE) { if (!gst_v4l2_decoder_dequeue_src (self->decoder, &frame_num)) { GST_ELEMENT_ERROR (self, STREAM, DECODE, ("Decoder did not produce a frame"), (NULL)); - gst_video_decoder_drop_frame (GST_VIDEO_DECODER (decoder), frame); - gst_h264_picture_unref (picture); - return GST_FLOW_ERROR; + goto error; } if (frame_num == picture->system_frame_number) @@ -906,7 +905,13 @@ finish_frame: gst_video_codec_frame_set_user_data (frame, NULL, NULL); gst_h264_picture_unref (picture); - return gst_video_decoder_finish_frame (GST_VIDEO_DECODER (self), frame); + return gst_video_decoder_finish_frame (vdec, frame); + +error: + gst_video_decoder_drop_frame (vdec, frame); + gst_h264_picture_unref (picture); + + return GST_FLOW_ERROR; } static void