aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Zern <jzern@google.com>2019-07-09 19:03:58 -0700
committerMichael Niedermayer <michael@niedermayer.cc>2019-11-14 23:30:37 +0100
commit7a026998b07ebfbf419d64106be11d9486312c91 (patch)
treefd3d32030d520f3a7ff4e97bb5d212a5234118e2
parent49b4d41ec1b33214aac0f3e51c0ca177e3dfeb37 (diff)
downloadffmpeg-7a026998b07ebfbf419d64106be11d9486312c91.tar.gz
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: James Zern <jzern@google.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit b1febda061955c6f4bfbc1a75918b5e75e7d7f80) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--libavcodec/utils.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index c587110af2..1a5f4e7e4f 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -630,6 +630,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;
@@ -1024,6 +1025,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
if (ret < 0) {
goto free_and_end;
}
+ codec_init_ok = 1;
}
ret=0;
@@ -1117,7 +1119,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)