diff mbox series

[FFmpeg-devel,19/21] avformat/tiertexseq: Simplify cleanup after read_header error

Message ID 20200322034756.29907-19-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel,01/21] avformat/nsvdec: Use av_packet_move_ref() for packet ownership transfer
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Andreas Rheinhardt March 22, 2020, 3:47 a.m. UTC
by setting the FF_INPUTFORMAT_HEADER_CLEANUP flag. Also check error
conditions for being negative instead of only nonzero (they couldn't be
positive here anyway).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/tiertexseq.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/tiertexseq.c b/libavformat/tiertexseq.c
index d7719e5acb..07c939a4d4 100644
--- a/libavformat/tiertexseq.c
+++ b/libavformat/tiertexseq.c
@@ -161,7 +161,7 @@  static int seq_parse_frame_data(SeqDemuxContext *seq, AVIOContext *pb)
             err = seq_fill_buffer(seq, pb, buffer_num[1 + i],
               offset_table[i],
               offset_table[e] - offset_table[i]);
-            if (err)
+            if (err < 0)
                 return err;
         }
     }
@@ -202,20 +202,16 @@  static int seq_read_header(AVFormatContext *s)
 
     /* init internal buffers */
     rc = seq_init_frame_buffers(seq, pb);
-    if (rc) {
-        seq_read_close(s);
+    if (rc < 0)
         return rc;
-    }
 
     seq->current_frame_offs = 0;
 
     /* preload (no audio data, just buffer operations related data) */
     for (i = 1; i <= 100; i++) {
         rc = seq_parse_frame_data(seq, pb);
-        if (rc) {
-            seq_read_close(s);
+        if (rc < 0)
             return rc;
-        }
     }
 
     seq->current_frame_pts = 0;
@@ -224,10 +220,8 @@  static int seq_read_header(AVFormatContext *s)
 
     /* initialize the video decoder stream */
     st = avformat_new_stream(s, NULL);
-    if (!st) {
-        seq_read_close(s);
+    if (!st)
         return AVERROR(ENOMEM);
-    }
 
     avpriv_set_pts_info(st, 32, 1, SEQ_FRAME_RATE);
     seq->video_stream_index = st->index;
@@ -239,10 +233,8 @@  static int seq_read_header(AVFormatContext *s)
 
     /* initialize the audio decoder stream */
     st = avformat_new_stream(s, NULL);
-    if (!st) {
-        seq_read_close(s);
+    if (!st)
         return AVERROR(ENOMEM);
-    }
 
     st->start_time = 0;
     avpriv_set_pts_info(st, 32, 1, SEQ_SAMPLE_RATE);
@@ -324,4 +316,5 @@  AVInputFormat ff_tiertexseq_demuxer = {
     .read_header    = seq_read_header,
     .read_packet    = seq_read_packet,
     .read_close     = seq_read_close,
+    .flags_internal = FF_INPUTFORMAT_HEADER_CLEANUP,
 };