From 6e160da49756415112f409dce5820a92ddd2af5a Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 16 Jul 2021 09:21:55 -0400 Subject: [PATCH] TT#14008 move avpkt alloc to encoder_new If encoder_config errors out for some reason, avpkt may end up uninitialised. Make sure there is an avpkt when flushing/closing the encoder. Also make the encoder input more resilient against half-initialised encoders for the same reason. closes #1312 Change-Id: I44ebcf6e35f1c383aa5c8202b5d9bbf968b0d5f1 --- lib/codeclib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/codeclib.c b/lib/codeclib.c index 24525d006..257985745 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -1231,6 +1231,7 @@ encoder_t *encoder_new(void) { encoder_t *ret = g_slice_alloc0(sizeof(*ret)); format_init(&ret->requested_format); format_init(&ret->actual_format); + ret->avpkt = av_packet_alloc(); return ret; } @@ -1315,8 +1316,6 @@ int encoder_config_fmtp(encoder_t *enc, const codec_def_t *def, int bitrate, int if (err) goto err; - enc->avpkt = av_packet_alloc(); - // output frame and fifo enc->frame = av_frame_alloc(); @@ -1458,6 +1457,8 @@ int encoder_input_data(encoder_t *enc, AVFrame *frame, enc->avpkt->size = 0; while (1) { + if (!enc->def || !enc->def->codec_type) + break; if (!enc->def->codec_type->encoder_input) break;