1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avformat/demux: Fix segfault due to avcodec_open2 failure

Fixes 'ffprobe 1_poc.mp4' segfault introduced with
commit 0021484d05

codec_close should not assume that the codec_id did not change.
This commit is contained in:
Pavel Koshevoy
2025-06-27 19:31:26 -06:00
parent 18c62245d7
commit 59a6660625

View File

@ -1292,9 +1292,15 @@ static int codec_close(FFStream *sti)
{ {
AVCodecContext *avctx_new = NULL; AVCodecContext *avctx_new = NULL;
AVCodecParameters *par_tmp = NULL; AVCodecParameters *par_tmp = NULL;
const AVCodec *new_codec = NULL;
int ret; int ret;
avctx_new = avcodec_alloc_context3(sti->avctx->codec); new_codec =
(sti->avctx->codec_id != sti->pub.codecpar->codec_id) ?
avcodec_find_decoder(sti->pub.codecpar->codec_id) :
sti->avctx->codec;
avctx_new = avcodec_alloc_context3(new_codec);
if (!avctx_new) { if (!avctx_new) {
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail; goto fail;