1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avcodec/mpegaudiodec*: Cleanup generically on init failure

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
Andreas Rheinhardt 2020-09-15 08:33:22 +02:00
parent e9831b1e98
commit c7867b6ed1
3 changed files with 5 additions and 8 deletions

View File

@ -116,5 +116,6 @@ AVCodec ff_mp3on4_decoder = {
.flush = flush_mp3on4, .flush = flush_mp3on4,
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P, .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
AV_SAMPLE_FMT_NONE }, AV_SAMPLE_FMT_NONE },
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}; };
#endif #endif

View File

@ -116,5 +116,6 @@ AVCodec ff_mp3on4float_decoder = {
.flush = flush_mp3on4, .flush = flush_mp3on4,
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
AV_SAMPLE_FMT_NONE }, AV_SAMPLE_FMT_NONE },
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}; };
#endif #endif

View File

@ -1908,16 +1908,14 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
// Allocate zeroed memory for the first decoder context // Allocate zeroed memory for the first decoder context
s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext)); s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext));
if (!s->mp3decctx[0]) if (!s->mp3decctx[0])
goto alloc_fail; return AVERROR(ENOMEM);
// Put decoder context in place to make init_decode() happy // Put decoder context in place to make init_decode() happy
avctx->priv_data = s->mp3decctx[0]; avctx->priv_data = s->mp3decctx[0];
ret = decode_init(avctx); ret = decode_init(avctx);
// Restore mp3on4 context pointer // Restore mp3on4 context pointer
avctx->priv_data = s; avctx->priv_data = s;
if (ret < 0) { if (ret < 0)
decode_close_mp3on4(avctx);
return ret; return ret;
}
s->mp3decctx[0]->adu_mode = 1; // Set adu mode s->mp3decctx[0]->adu_mode = 1; // Set adu mode
/* Create a separate codec/context for each frame (first is already ok). /* Create a separate codec/context for each frame (first is already ok).
@ -1926,7 +1924,7 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
for (i = 1; i < s->frames; i++) { for (i = 1; i < s->frames; i++) {
s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext)); s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext));
if (!s->mp3decctx[i]) if (!s->mp3decctx[i])
goto alloc_fail; return AVERROR(ENOMEM);
s->mp3decctx[i]->adu_mode = 1; s->mp3decctx[i]->adu_mode = 1;
s->mp3decctx[i]->avctx = avctx; s->mp3decctx[i]->avctx = avctx;
s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp; s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp;
@ -1934,9 +1932,6 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
} }
return 0; return 0;
alloc_fail:
decode_close_mp3on4(avctx);
return AVERROR(ENOMEM);
} }