Re: [FFmpeg-devel] [PATCH] avcodec/utils, avcodec_open2: close codec on failure

2019-07-10 Thread Michael Niedermayer
On Tue, Jul 09, 2019 at 07:03:58PM -0700, James Zern wrote:
> 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 
> ---
>  libavcodec/utils.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)

will apply

thanks

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avcodec/utils, avcodec_open2: close codec on failure

2019-07-09 Thread James Zern
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 
---
 libavcodec/utils.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 1b1feca38c..9ff9628f7f 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -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)
-- 
2.22.0.410.gd8fdbe21b5-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".