Commit b1febda0 authored by James Zern's avatar James Zern Committed by Michael Niedermayer

avcodec/utils, avcodec_open2: close codec on failure

after a successful init if the function fails for another reason close
the codec without requiring FF_CODEC_CAP_INIT_CLEANUP which is meant to
cover init failures themselves. fixes a memory leak in those cases.

BUG=oss-fuzz:15529
Signed-off-by: 's avatarJames Zern <jzern@google.com>
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 94d45a13
......@@ -542,6 +542,7 @@ int attribute_align_arg ff_codec_open2_recursive(AVCodecContext *avctx, const AV
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
{
int ret = 0;
int codec_init_ok = 0;
AVDictionary *tmp = NULL;
const AVPixFmtDescriptor *pixdesc;
......@@ -935,6 +936,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
if (ret < 0) {
goto free_and_end;
}
codec_init_ok = 1;
}
ret=0;
......@@ -1023,7 +1025,8 @@ end:
return ret;
free_and_end:
if (avctx->codec &&
(avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP))
(codec_init_ok ||
(avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP)))
avctx->codec->close(avctx);
if (codec->priv_class && codec->priv_data_size)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment