diff mbox series

[FFmpeg-devel,16/34] avformat/asfenc: Add deinit function

Message ID AM7PR03MB666005CFBA6D0139EB85F4FF8FD29@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 87a4138d4b753c1ab41d0f8cb6891586adec471f
Headers show
Series [FFmpeg-devel,01/11] avformat/mux: Sanitize packets without data and side-data | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 6, 2021, 2:27 a.m. UTC
Fixes leaks when the trailer is never written.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/asfenc.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
index 8e9b7ffc28..e4d74c80cb 100644
--- a/libavformat/asfenc.c
+++ b/libavformat/asfenc.c
@@ -765,8 +765,6 @@  static int asf_write_header(AVFormatContext *s)
      * data_size - asf->data_offset at the moment this function is done.
      * It is needed to use asf as a streamable format. */
     if (asf_write_header1(s, 0, DATA_HEADER_SIZE) < 0) {
-        //av_free(asf);
-        av_freep(&asf->index_ptr);
         return -1;
     }
 
@@ -1110,10 +1108,16 @@  static int asf_write_trailer(AVFormatContext *s)
         asf_write_header1(s, file_size, data_size - asf->data_offset);
     }
 
-    av_freep(&asf->index_ptr);
     return 0;
 }
 
+static void asf_deinit(AVFormatContext *s)
+{
+    ASFContext *const asf = s->priv_data;
+
+    av_freep(&asf->index_ptr);
+}
+
 static const AVOption asf_options[] = {
     { "packet_size", "Packet size", offsetof(ASFContext, packet_size), AV_OPT_TYPE_INT, {.i64 = 3200}, PACKET_SIZE_MIN, PACKET_SIZE_MAX, AV_OPT_FLAG_ENCODING_PARAM },
     { NULL },
@@ -1141,6 +1145,7 @@  const AVOutputFormat ff_asf_muxer = {
     .flags          = AVFMT_GLOBALHEADER,
     .codec_tag      = asf_codec_tags,
     .priv_class        = &asf_muxer_class,
+    .deinit         = asf_deinit,
 };
 #endif /* CONFIG_ASF_MUXER */
 
@@ -1159,5 +1164,6 @@  const AVOutputFormat ff_asf_stream_muxer = {
     .flags          = AVFMT_GLOBALHEADER,
     .codec_tag      = asf_codec_tags,
     .priv_class     = &asf_muxer_class,
+    .deinit         = asf_deinit,
 };
 #endif /* CONFIG_ASF_STREAM_MUXER */