diff mbox series

[FFmpeg-devel,34/45] avcodec/smvjpegdec: Cleanup generically on init failure

Message ID 20201127010249.2724610-34-andreas.rheinhardt@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel,01/45] avcodec/a64multienc: Fix memleak upon init failure
Related show

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/smvjpegdec.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/smvjpegdec.c b/libavcodec/smvjpegdec.c
index 32756b54f3..807d990d00 100644
--- a/libavcodec/smvjpegdec.c
+++ b/libavcodec/smvjpegdec.c
@@ -105,37 +105,29 @@  static av_cold int smvjpeg_decode_init(AVCodecContext *avctx)
         return AVERROR(ENOMEM);
 
     s->picture[1] = av_frame_alloc();
-    if (!s->picture[1]) {
-        av_frame_free(&s->picture[0]);
+    if (!s->picture[1])
         return AVERROR(ENOMEM);
-    }
 
     s->jpg.picture_ptr      = s->picture[0];
 
     codec = avcodec_find_decoder(AV_CODEC_ID_MJPEG);
     if (!codec) {
         av_log(avctx, AV_LOG_ERROR, "MJPEG codec not found\n");
-        smvjpeg_decode_end(avctx);
         return AVERROR_DECODER_NOT_FOUND;
     }
 
     s->avctx = avcodec_alloc_context3(codec);
-    if (!s->avctx) {
-        smvjpeg_decode_end(avctx);
+    if (!s->avctx)
         return AVERROR(ENOMEM);
-    }
 
     av_dict_set(&thread_opt, "threads", "1", 0);
     s->avctx->refcounted_frames = 1;
     s->avctx->flags = avctx->flags;
     s->avctx->idct_algo = avctx->idct_algo;
-    if ((ret = ff_codec_open2_recursive(s->avctx, codec, &thread_opt)) < 0) {
+    if ((ret = ff_codec_open2_recursive(s->avctx, codec, &thread_opt)) < 0)
         av_log(avctx, AV_LOG_ERROR, "MJPEG codec failed to open\n");
-    }
     av_dict_free(&thread_opt);
 
-    if (ret < 0)
-        smvjpeg_decode_end(avctx);
     return ret;
 }
 
@@ -219,4 +211,5 @@  AVCodec ff_smvjpeg_decoder = {
     .close          = smvjpeg_decode_end,
     .decode         = smvjpeg_decode_frame,
     .priv_class     = &smvjpegdec_class,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };