diff mbox series

[FFmpeg-devel,19/30] avcodec/opusdec: Cleanup generically in init failure

Message ID 20201230233157.1055287-19-andreas.rheinhardt@gmail.com
State Accepted
Commit 9f36a5a1cc2e5739b3c9f7a35c25c66b2eeb3b33
Headers show
Series [FFmpeg-devel,01/30] avcodec/opustab: Make array static | expand

Checks

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

Commit Message

Andreas Rheinhardt Dec. 30, 2020, 11:31 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/opusdec.c | 33 +++++++++++----------------------
 1 file changed, 11 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/opusdec.c b/libavcodec/opusdec.c
index b09a542c86..24e90a3761 100644
--- a/libavcodec/opusdec.c
+++ b/libavcodec/opusdec.c
@@ -630,17 +630,14 @@  static av_cold int opus_decode_init(AVCodecContext *avctx)
 
     /* find out the channel configuration */
     ret = ff_opus_parse_extradata(avctx, c);
-    if (ret < 0) {
-        av_freep(&c->fdsp);
+    if (ret < 0)
         return ret;
-    }
 
     /* allocate and init each independent decoder */
     c->streams = av_mallocz_array(c->nb_streams, sizeof(*c->streams));
     if (!c->streams) {
         c->nb_streams = 0;
-        ret = AVERROR(ENOMEM);
-        goto fail;
+        return AVERROR(ENOMEM);
     }
 
     for (i = 0; i < c->nb_streams; i++) {
@@ -660,10 +657,8 @@  static av_cold int opus_decode_init(AVCodecContext *avctx)
         s->fdsp = c->fdsp;
 
         s->swr =swr_alloc();
-        if (!s->swr) {
-            ret = AVERROR(ENOMEM);
-            goto fail;
-        }
+        if (!s->swr)
+            return AVERROR(ENOMEM);
 
         layout = (s->output_channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
         av_opt_set_int(s->swr, "in_sample_fmt",      avctx->sample_fmt,  0);
@@ -675,31 +670,24 @@  static av_cold int opus_decode_init(AVCodecContext *avctx)
 
         ret = ff_silk_init(avctx, &s->silk, s->output_channels);
         if (ret < 0)
-            goto fail;
+            return ret;
 
         ret = ff_celt_init(avctx, &s->celt, s->output_channels, c->apply_phase_inv);
         if (ret < 0)
-            goto fail;
+            return ret;
 
         s->celt_delay = av_audio_fifo_alloc(avctx->sample_fmt,
                                             s->output_channels, 1024);
-        if (!s->celt_delay) {
-            ret = AVERROR(ENOMEM);
-            goto fail;
-        }
+        if (!s->celt_delay)
+            return AVERROR(ENOMEM);
 
         s->sync_buffer = av_audio_fifo_alloc(avctx->sample_fmt,
                                              s->output_channels, 32);
-        if (!s->sync_buffer) {
-            ret = AVERROR(ENOMEM);
-            goto fail;
-        }
+        if (!s->sync_buffer)
+            return AVERROR(ENOMEM);
     }
 
     return 0;
-fail:
-    opus_decode_close(avctx);
-    return ret;
 }
 
 #define OFFSET(x) offsetof(OpusContext, x)
@@ -728,4 +716,5 @@  AVCodec ff_opus_decoder = {
     .decode          = opus_decode_packet,
     .flush           = opus_decode_flush,
     .capabilities    = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_CHANNEL_CONF,
+    .caps_internal   = FF_CODEC_CAP_INIT_CLEANUP,
 };