[FFmpeg-devel] [PATCH 1/2] avformat: fix memory corruption when free AVStream

tony_nie at realsil.com.cn tony_nie at realsil.com.cn
Wed Mar 5 03:33:33 CET 2014


From: tony_nie <tony_nie at realsil.com.cn>

Make shure buffer had beed alloced before free it.

Signed-off-by: tony_nie <tony_nie at realsil.com.cn>
---
 libavformat/utils.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 4e262b1..658d373 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3521,10 +3521,18 @@ void ff_free_stream(AVFormatContext *s, AVStream *st) {
     av_freep(&st->codec->extradata);
     av_freep(&st->codec->subtitle_header);
     av_freep(&st->codec);
-    av_freep(&st->priv_data);
-    if (st->info)
-        av_freep(&st->info->duration_error);
-    av_freep(&st->info);
+
+    if (st->priv_data) {
+        av_freep(&st->priv_data);
+    }
+
+    if (st->info) {
+        if (st->info->duration_error) {
+            av_freep(&st->info->duration_error);
+        }
+        av_freep(&st->info);
+    }
+
     av_freep(&s->streams[ --s->nb_streams ]);
 }
 
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list