[FFmpeg-cvslog] nut: Make sure to clean up on read_header failure

Luca Barbato git at videolan.org
Mon Jun 1 13:28:42 CEST 2015


ffmpeg | branch: release/2.2 | Luca Barbato <lu_zero at gentoo.org> | Wed Apr 29 21:29:49 2015 +0200| [c34d1099db6f9bc49f30eb3141f87c42b01a3714] | committer: Reinhard Tartler

nut: Make sure to clean up on read_header failure

Based on Andreas Cadhalpun <Andreas.Cadhalpun at googlemail.com> work.

CC: libav-stable at libav.org
(cherry picked from commit 1f64b018cbec018fa66a4a20f79958d9707913de)
Signed-off-by: Reinhard Tartler <siretart at tauware.de>

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

 libavformat/nutdec.c |   39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 0da7c4b..56bffe0 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -659,6 +659,20 @@ fail:
     return ret;
 }
 
+static int nut_read_close(AVFormatContext *s)
+{
+    NUTContext *nut = s->priv_data;
+    int i;
+
+    av_freep(&nut->time_base);
+    av_freep(&nut->stream);
+    ff_nut_free_sp(nut);
+    for (i = 1; i < nut->header_count; i++)
+        av_freep(&nut->header[i]);
+
+    return 0;
+}
+
 static int nut_read_header(AVFormatContext *s)
 {
     NUTContext *nut = s->priv_data;
@@ -674,7 +688,7 @@ static int nut_read_header(AVFormatContext *s)
         pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
         if (pos < 0 + 1) {
             av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
-            return AVERROR_INVALIDDATA;
+            goto fail;
         }
     } while (decode_main_header(nut) < 0);
 
@@ -684,7 +698,7 @@ static int nut_read_header(AVFormatContext *s)
         pos = find_startcode(bc, STREAM_STARTCODE, pos) + 1;
         if (pos < 0 + 1) {
             av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n");
-            return AVERROR_INVALIDDATA;
+            goto fail;
         }
         if (decode_stream_header(nut) >= 0)
             initialized_stream_count++;
@@ -698,7 +712,7 @@ static int nut_read_header(AVFormatContext *s)
 
         if (startcode == 0) {
             av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
-            return AVERROR_INVALIDDATA;
+            goto fail;
         } else if (startcode == SYNCPOINT_STARTCODE) {
             nut->next_startcode = startcode;
             break;
@@ -721,6 +735,11 @@ static int nut_read_header(AVFormatContext *s)
     ff_metadata_conv_ctx(s, NULL, ff_nut_metadata_conv);
 
     return 0;
+
+fail:
+    nut_read_close(s);
+
+    return AVERROR_INVALIDDATA;
 }
 
 static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id,
@@ -987,20 +1006,6 @@ static int read_seek(AVFormatContext *s, int stream_index,
     return 0;
 }
 
-static int nut_read_close(AVFormatContext *s)
-{
-    NUTContext *nut = s->priv_data;
-    int i;
-
-    av_freep(&nut->time_base);
-    av_freep(&nut->stream);
-    ff_nut_free_sp(nut);
-    for (i = 1; i < nut->header_count; i++)
-        av_freep(&nut->header[i]);
-
-    return 0;
-}
-
 AVInputFormat ff_nut_demuxer = {
     .name           = "nut",
     .long_name      = NULL_IF_CONFIG_SMALL("NUT"),



More information about the ffmpeg-cvslog mailing list