[FFmpeg-cvslog] avformat/nutenc: implement deinit()

Michael Niedermayer git at videolan.org
Thu Jan 21 13:19:20 CET 2016


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Thu Jan 21 13:07:07 2016 +0100| [56c182c4d716b8b72156ff57a0c8d72087db8549] | committer: Michael Niedermayer

avformat/nutenc: implement deinit()

Should prevent some leaks if header writing fails

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=56c182c4d716b8b72156ff57a0c8d72087db8549
---

 libavformat/nut.c    |    6 ++++--
 libavformat/nutenc.c |   18 +++++++++++++-----
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/libavformat/nut.c b/libavformat/nut.c
index 30989a4..7d5f1ba 100644
--- a/libavformat/nut.c
+++ b/libavformat/nut.c
@@ -288,8 +288,10 @@ static int enu_free(void *opaque, void *elem)
 
 void ff_nut_free_sp(NUTContext *nut)
 {
-    av_tree_enumerate(nut->syncpoints, NULL, NULL, enu_free);
-    av_tree_destroy(nut->syncpoints);
+    if (nut->syncpoints) {
+        av_tree_enumerate(nut->syncpoints, NULL, NULL, enu_free);
+        av_tree_destroy(nut->syncpoints);
+    }
 }
 
 const Dispositions ff_nut_dispositions[] = {
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index ae097b3..b6582ef 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -1174,7 +1174,7 @@ static int nut_write_trailer(AVFormatContext *s)
 {
     NUTContext *nut = s->priv_data;
     AVIOContext *bc = s->pb, *dyn_bc;
-    int i, ret;
+    int ret;
 
     while (nut->header_count < 3)
         write_headers(s, bc);
@@ -1186,15 +1186,22 @@ static int nut_write_trailer(AVFormatContext *s)
         put_packet(nut, bc, dyn_bc, 1, INDEX_STARTCODE);
     }
 
+    return 0;
+}
+
+static void nut_write_deinit(AVFormatContext *s)
+{
+    NUTContext *nut = s->priv_data;
+    int i;
+
     ff_nut_free_sp(nut);
-    for (i=0; i<s->nb_streams; i++)
-        av_freep(&nut->stream[i].keyframe_pts);
+    if (nut->stream)
+        for (i=0; i<s->nb_streams; i++)
+            av_freep(&nut->stream[i].keyframe_pts);
 
     av_freep(&nut->stream);
     av_freep(&nut->chapter);
     av_freep(&nut->time_base);
-
-    return 0;
 }
 
 #define OFFSET(x) offsetof(NUTContext, x)
@@ -1227,6 +1234,7 @@ AVOutputFormat ff_nut_muxer = {
     .write_header   = nut_write_header,
     .write_packet   = nut_write_packet,
     .write_trailer  = nut_write_trailer,
+    .deinit         = nut_write_deinit,
     .flags          = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
     .codec_tag      = ff_nut_codec_tags,
     .priv_class     = &class,



More information about the ffmpeg-cvslog mailing list