summaryrefslogtreecommitdiff
path: root/libavformat/flvenc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2019-10-23 14:59:42 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-07-09 20:16:39 +0200
commit6f5e0a7294d83145819e1b0203eca1c2e68e135f (patch)
treed72eee31adac14b9d08abc49985544bb26044b4e /libavformat/flvenc.c
parent75a2d25a6fe83d6c7aaf7d7ae27ce3a2e719d984 (diff)
downloadffmpeg-6f5e0a7294d83145819e1b0203eca1c2e68e135f.tar.gz
avformat/flvenc: Add deinit function
Fixes memleaks when the trailer is never written or when shift_data() fails when writing the trailer. Reviewed-by: Steven Liu <lingjiujianke@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/flvenc.c')
-rw-r--r--libavformat/flvenc.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 4e65ba4066..770ca319ed 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -733,7 +733,7 @@ static int flv_write_trailer(AVFormatContext *s)
int64_t cur_pos = avio_tell(s->pb);
if (build_keyframes_idx) {
- FLVFileposition *newflv_posinfo, *p;
+ const FLVFileposition *newflv_posinfo;
avio_seek(pb, flv->videosize_offset, SEEK_SET);
put_amf_double(pb, flv->videosize);
@@ -768,19 +768,6 @@ static int flv_write_trailer(AVFormatContext *s)
put_amf_double(pb, newflv_posinfo->keyframe_timestamp);
}
- newflv_posinfo = flv->head_filepositions;
- while (newflv_posinfo) {
- p = newflv_posinfo->next;
- if (p) {
- newflv_posinfo->next = p->next;
- av_free(p);
- p = NULL;
- } else {
- av_free(newflv_posinfo);
- newflv_posinfo = NULL;
- }
- }
-
put_amf_string(pb, "");
avio_w8(pb, AMF_END_OF_OBJECT);
@@ -1047,6 +1034,20 @@ static int flv_check_bitstream(AVFormatContext *s, AVStream *st,
return ret;
}
+static void flv_deinit(AVFormatContext *s)
+{
+ FLVContext *flv = s->priv_data;
+ FLVFileposition *filepos = flv->head_filepositions;
+
+ while (filepos) {
+ FLVFileposition *next = filepos->next;
+ av_free(filepos);
+ filepos = next;
+ }
+ flv->filepositions = flv->head_filepositions = NULL;
+ flv->filepositions_count = 0;
+}
+
static const AVOption options[] = {
{ "flvflags", "FLV muxer flags", offsetof(FLVContext, flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
{ "aac_seq_header_detect", "Put AAC sequence header based on stream data", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_AAC_SEQ_HEADER_DETECT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
@@ -1076,6 +1077,7 @@ const AVOutputFormat ff_flv_muxer = {
.write_header = flv_write_header,
.write_packet = flv_write_packet,
.write_trailer = flv_write_trailer,
+ .deinit = flv_deinit,
.check_bitstream= flv_check_bitstream,
.codec_tag = (const AVCodecTag* const []) {
flv_video_codec_ids, flv_audio_codec_ids, 0