From a31106d84976bd28e56de35ee8085eebfc6c5e4d Mon Sep 17 00:00:00 2001 From: Dale Curtis Date: Fri, 2 Aug 2024 16:44:21 +0000 Subject: [PATCH] lavf/demux: don't reallocate a AVCodecContext when closing a non-open codec. This results in an unnecessary ~800k allocation with H.264. A nearby callsite uses avcodec_is_open() to avoid this, so do the same when exiting avformat_find_stream_info(). Signed-off-by: Dale Curtis Signed-off-by: Anton Khirnov --- libavformat/demux.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libavformat/demux.c b/libavformat/demux.c index dc65f9ad91..4fd22c4934 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -3102,9 +3102,12 @@ find_stream_info_err: av_freep(&sti->info); } - err = codec_close(sti); - if (err < 0 && ret >= 0) - ret = err; + if (avcodec_is_open(sti->avctx)) { + err = codec_close(sti); + if (err < 0 && ret >= 0) + ret = err; + } + av_bsf_free(&sti->extract_extradata.bsf); } if (ic->pb) {