diff mbox series

[FFmpeg-devel,02/10] avformat/segment: Fix leak of duration/framenumber lists upon error

Message ID 20200907024952.11697-2-andreas.rheinhardt@gmail.com
State Accepted
Commit 4b836c86132feb67ca10e383988884dd67bcd19a
Headers show
Series [FFmpeg-devel,01/10] avformat/segment: Don't overwrite AVCodecParameters after init | expand


Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 7, 2020, 2:49 a.m. UTC
The code to free them is not in the segment muxer's deinit function,
but in its write_trailer function which means that these lists leak if
write_trailer isn't called after their allocation. This happens e.g. if
the given lists are invalid (e.g. consisting only of ',' (which delimit
entries)), so that parsing them fails and so does the muxer's init
function; write_trailer is then never called.

This has been fixed by moving the code to free them to the deinit

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
 libavformat/segment.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series


diff --git a/libavformat/segment.c b/libavformat/segment.c
index 0c9b93725d..0c96c8c50c 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -663,6 +663,8 @@  static void seg_free(AVFormatContext *s)
     ff_format_io_close(seg->avf, &seg->list_pb);
     seg->avf = NULL;
+    av_freep(&seg->times);
+    av_freep(&seg->frames);
 static int seg_init(AVFormatContext *s)
@@ -991,8 +993,6 @@  fail:
         ff_format_io_close(s, &seg->list_pb);
-    av_freep(&seg->times);
-    av_freep(&seg->frames);
     cur = seg->segment_list_entries;