[FFmpeg-devel,4/4] avformat/flvenc: Add deinit function

Submitted by Andreas Rheinhardt on Oct. 25, 2019, 9:11 a.m.

Details

Message ID 20191025091147.5298-3-andreas.rheinhardt@gmail.com
State New
Headers show

Commit Message

Andreas Rheinhardt Oct. 25, 2019, 9:11 a.m.
Fixes memleaks when the trailer is never written or when shift_data()
fails when writing the trailer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/flvenc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index a2bd791c59..228900f028 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -810,8 +810,6 @@  static int flv_write_trailer(AVFormatContext *s)
             put_amf_double(pb, flv_posinfo[i].keyframe_timestamp);
         }
 
-        av_freep(&flv->filepositions);
-
         put_amf_string(pb, "");
         avio_w8(pb, AMF_END_OF_OBJECT);
 
@@ -1076,6 +1074,14 @@  static int flv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
     return ret;
 }
 
+static void flv_deinit(AVFormatContext *s)
+{
+    FLVContext *flv = s->priv_data;
+
+    av_freep(&flv->filepositions);
+    flv->filepositions_count = flv->filepositions_allocated = 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" },
@@ -1105,6 +1111,7 @@  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