This fixes leaks when the trailer is never written. Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@gmail.com> --- The allocation of the filename is btw currently unchecked. Actually, using a flexible array member for it would be advantageous (it could then be allocated and freed together with its SegmentListEntry). Flexible array members are C99. Are they allowed or do we support systems that don't support them?
libavformat/segment.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libavformat/segment.c b/libavformat/segment.c index 55d7f62ca0..d895e6a678 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -661,6 +661,8 @@ static int select_reference_stream(AVFormatContext *s) static void seg_free(AVFormatContext *s) { SegmentContext *seg = s->priv_data; + SegmentListEntry *cur; + ff_format_io_close(s, &seg->list_pb); if (seg->avf) { if (seg->is_nullctx) @@ -673,6 +675,14 @@ static void seg_free(AVFormatContext *s) av_freep(&seg->times); av_freep(&seg->frames); av_freep(&seg->cur_entry.filename); + + cur = seg->segment_list_entries; + while (cur) { + SegmentListEntry *next = cur->next; + av_freep(&cur->filename); + av_free(cur); + cur = next; + } } static int seg_init(AVFormatContext *s) @@ -981,7 +991,6 @@ static int seg_write_trailer(struct AVFormatContext *s) { SegmentContext *seg = s->priv_data; AVFormatContext *oc = seg->avf; - SegmentListEntry *cur, *next; int ret = 0; if (!oc) @@ -1004,14 +1013,6 @@ fail: av_opt_free(seg); - cur = seg->segment_list_entries; - while (cur) { - next = cur->next; - av_freep(&cur->filename); - av_free(cur); - cur = next; - } - avformat_free_context(oc); seg->avf = NULL; return ret; -- 2.20.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".