]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/mxpegdec: Fix memleaks upon init failure
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 26 Nov 2020 21:16:13 +0000 (22:16 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Fri, 4 Dec 2020 14:46:46 +0000 (15:46 +0100)
Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/mjpegdec.c
libavcodec/mxpegdec.c

index 6cf8014490efee77383337f7bbdb794893212b73..c2d946752e670fc175db70ef3442971a2bc58e6b 100644 (file)
@@ -2815,6 +2815,8 @@ the_end_no_picture:
     return buf_ptr - buf;
 }
 
+/* mxpeg may call the following function (with a blank MJpegDecodeContext)
+ * even without having called ff_mjpeg_decode_init(). */
 av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
 {
     MJpegDecodeContext *s = avctx->priv_data;
index 55ec6e928e2f68394c24b365e7ec0e0795111fff..725e435118d1669618d6629542d7e5b347e70c13 100644 (file)
@@ -67,10 +67,8 @@ static av_cold int mxpeg_decode_init(AVCodecContext *avctx)
 
     s->picture[0] = av_frame_alloc();
     s->picture[1] = av_frame_alloc();
-    if (!s->picture[0] || !s->picture[1]) {
-        mxpeg_decode_end(avctx);
+    if (!s->picture[0] || !s->picture[1])
         return AVERROR(ENOMEM);
-    }
 
     s->jpg.picture_ptr      = s->picture[0];
     return ff_mjpeg_decode_init(avctx);
@@ -351,5 +349,5 @@ AVCodec ff_mxpeg_decoder = {
     .decode         = mxpeg_decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
     .max_lowres     = 3,
-    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };