diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-11-26 22:16:13 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2021-02-27 07:21:00 +0100 |
commit | fbb9368226d693c99d9b0aee672c59ed1a36785b (patch) | |
tree | 2e35048efefa62324cc471f8b6389ed66803ce71 | |
parent | eda1ed6f914a762a30e13e538f380355e8b7337a (diff) | |
download | ffmpeg-fbb9368226d693c99d9b0aee672c59ed1a36785b.tar.gz |
avcodec/mxpegdec: Fix memleaks upon init failure
Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
(cherry picked from commit 9de6688cc4216381e155a5b3f7d88c26806db93d)
-rw-r--r-- | libavcodec/mjpegdec.c | 2 | ||||
-rw-r--r-- | libavcodec/mxpegdec.c | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index a46af58f21..92cb9d1e4c 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -2803,6 +2803,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 f89226fefa..763ce5871d 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); @@ -352,5 +350,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, }; |