Hello,

Attached path fixes potential memory leak in output format context when av_interleaved_write_frame() is used. This function can use AVFormatContext.packet_buffer for packet ordering, but this buffer is not feed later in avformat_free_context().
The Valgrind utiluty clearly shows this leak.

Note polease that when closing input context with avformat_close_input(AVFormatContext **ps) , the packet_buffer is correctly freed by flush_packet_queue(s) -> free_packet_buffer(&s->packet_buffer, &s->packet_buffer_end). But free_packet_buffer() is declared as static in utils.c and can not be called directly from application code.

So, I propose to add this call into avformat_free_context() to avoid memory leaks on output.

Regards,
    Andrey Myznikov











>From 9d836666000821da8bbe1d0114c61f2dc703ea65 Mon Sep 17 00:00:00 2001
From: Andrey Myznikov <andrey.myzni...@gmail.com>
Date: Fri, 15 Aug 2014 17:25:15 +0300
Subject: [PATCH] Fix packet_buffer memory leak in avformat_free_context

---
 libavformat/utils.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 5d146d6..34eca17 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3525,6 +3525,7 @@ void avformat_free_context(AVFormatContext *s)
     av_dict_free(&s->metadata);
     av_freep(&s->streams);
     av_freep(&s->internal);
+    free_packet_buffer(&s->packet_buffer, &s->packet_buffer_end);
     av_free(s);
 }
 
-- 
2.0.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to