diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-12-28 17:58:43 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-12-31 23:35:10 +0100 |
commit | 9f36a5a1cc2e5739b3c9f7a35c25c66b2eeb3b33 (patch) | |
tree | 9e6a97d11418abfcb5ae36358d3e2aed69874375 | |
parent | f03eade8690d9914fce574afb1795f16c036bb6b (diff) | |
download | ffmpeg-9f36a5a1cc2e5739b3c9f7a35c25c66b2eeb3b33.tar.gz |
avcodec/opusdec: Cleanup generically on init failure
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
-rw-r--r-- | libavcodec/opusdec.c | 33 |
1 files changed, 11 insertions, 22 deletions
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, }; |