[FFmpeg-devel] [PATCH] avcodec/codec_par: ensure the target AVCodecContext doesn't have stale allocations on error
James Almer
jamrial at gmail.com
Sat Oct 12 20:13:14 EEST 2024
This copies the behavior of avcodec_parameters_from_context().
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavcodec/codec_par.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c
index 790ea01d10..d178b02ff1 100644
--- a/libavcodec/codec_par.c
+++ b/libavcodec/codec_par.c
@@ -205,6 +205,11 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
{
int ret;
+ av_channel_layout_uninit(&codec->ch_layout);
+ av_packet_side_data_free(&codec->coded_side_data, &codec->nb_coded_side_data);
+ av_freep(&codec->extradata);
+ codec->extradata_size = 0;
+
codec->codec_type = par->codec_type;
codec->codec_id = par->codec_id;
codec->codec_tag = par->codec_tag;
@@ -249,8 +254,6 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
break;
}
- av_freep(&codec->extradata);
- codec->extradata_size = 0;
if (par->extradata) {
codec->extradata = av_mallocz(par->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!codec->extradata)
@@ -259,7 +262,6 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
codec->extradata_size = par->extradata_size;
}
- av_packet_side_data_free(&codec->coded_side_data, &codec->nb_coded_side_data);
ret = codec_parameters_copy_side_data(&codec->coded_side_data, &codec->nb_coded_side_data,
par->coded_side_data, par->nb_coded_side_data);
if (ret < 0)
--
2.46.2
More information about the ffmpeg-devel
mailing list