[FFmpeg-devel] [PATCH 30/30] avcodec/mpegaudiodec*: Cleanup generically on init failure

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Tue Sep 15 10:40:00 EEST 2020


Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavcodec/mpegaudiodec_fixed.c    | 1 +
 libavcodec/mpegaudiodec_float.c    | 1 +
 libavcodec/mpegaudiodec_template.c | 9 ++-------
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/libavcodec/mpegaudiodec_fixed.c b/libavcodec/mpegaudiodec_fixed.c
index ad7ceb20b6..a2c433954b 100644
--- a/libavcodec/mpegaudiodec_fixed.c
+++ b/libavcodec/mpegaudiodec_fixed.c
@@ -116,5 +116,6 @@ AVCodec ff_mp3on4_decoder = {
     .flush          = flush_mp3on4,
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
                                                       AV_SAMPLE_FMT_NONE },
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };
 #endif
diff --git a/libavcodec/mpegaudiodec_float.c b/libavcodec/mpegaudiodec_float.c
index 0defdf3af1..4aa52d4f53 100644
--- a/libavcodec/mpegaudiodec_float.c
+++ b/libavcodec/mpegaudiodec_float.c
@@ -116,5 +116,6 @@ AVCodec ff_mp3on4float_decoder = {
     .flush          = flush_mp3on4,
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
                                                       AV_SAMPLE_FMT_NONE },
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };
 #endif
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index 8ed2f74eee..68e6dbfdf8 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -1906,16 +1906,14 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
     // Allocate zeroed memory for the decoder contexts
     s->mp3decctx = av_mallocz_array(sizeof(MPADecodeContext), s->frames);
     if (!s->mp3decctx)
-        goto alloc_fail;
+        return AVERROR(ENOMEM);
     // Put decoder context in place to make init_decode() happy
     avctx->priv_data = s->mp3decctx;
     ret = decode_init(avctx);
     // Restore mp3on4 context pointer
     avctx->priv_data = s;
-    if (ret < 0) {
-        decode_close_mp3on4(avctx);
+    if (ret < 0)
         return ret;
-    }
     s->mp3decctx[0].adu_mode = 1; // Set adu mode
 
     /* Create a separate codec/context for each frame (first is already ok).
@@ -1929,9 +1927,6 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
     }
 
     return 0;
-alloc_fail:
-    decode_close_mp3on4(avctx);
-    return AVERROR(ENOMEM);
 }
 
 
-- 
2.25.1



More information about the ffmpeg-devel mailing list