diff mbox series

[FFmpeg-devel,36/45] avcodec/mxpegdec: Fix memleaks upon init failure

Message ID 20201127010249.2724610-36-andreas.rheinhardt@gmail.com
State Accepted
Commit 9de6688cc4216381e155a5b3f7d88c26806db93d
Headers show
Series [FFmpeg-devel,01/45] avcodec/a64multienc: Fix memleak upon init failure | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 27, 2020, 1:02 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/mjpegdec.c | 2 ++
 libavcodec/mxpegdec.c | 6 ++----
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Anton Khirnov Dec. 4, 2020, 12:02 p.m. UTC | #1
Quoting Andreas Rheinhardt (2020-11-27 02:02:40)
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/mjpegdec.c | 2 ++
>  libavcodec/mxpegdec.c | 6 ++----
>  2 files changed, 4 insertions(+), 4 deletions(-)

This use of mjpeg by other decoders is an ugly mess, but the patch looks
ok
diff mbox series

Patch

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 6cf8014490..c2d946752e 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -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;
diff --git a/libavcodec/mxpegdec.c b/libavcodec/mxpegdec.c
index 55ec6e928e..725e435118 100644
--- a/libavcodec/mxpegdec.c
+++ b/libavcodec/mxpegdec.c
@@ -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,
 };