diff mbox series

[FFmpeg-devel,36/54] avformat/pp_bnk: Simplify cleanup after read_header failure

Message ID HE1PR0301MB2154A3E011CFABCC1DCE83748F309@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit b00c9c74af5e52fdc92670bda0de128891f9d7c8
Headers show
Series [FFmpeg-devel,01/54] avformat: Add internal flags for AV(In|Out)putFormat
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt June 15, 2021, 11:32 p.m. UTC
by setting the FF_FMT_INIT_CLEANUP flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/pp_bnk.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/pp_bnk.c b/libavformat/pp_bnk.c
index 9455a575b7..c500ac7d9e 100644
--- a/libavformat/pp_bnk.c
+++ b/libavformat/pp_bnk.c
@@ -144,7 +144,7 @@  static int pp_bnk_read_header(AVFormatContext *s)
 
         ret = avio_read(s->pb, buf, PP_BNK_TRACK_SIZE);
         if (ret < 0 && ret != AVERROR_EOF)
-            goto fail;
+            return ret;
 
         /* Short byte-count or EOF, we have a truncated file. */
         if (ret != PP_BNK_TRACK_SIZE) {
@@ -157,15 +157,12 @@  static int pp_bnk_read_header(AVFormatContext *s)
         pp_bnk_parse_track(&e, buf);
 
         /* The individual sample rates of all tracks must match that of the file header. */
-        if (e.sample_rate != hdr.sample_rate) {
-            ret = AVERROR_INVALIDDATA;
-            goto fail;
-        }
+        if (e.sample_rate != hdr.sample_rate)
+            return AVERROR_INVALIDDATA;
 
         if (e.always1_1 != 1 || e.always1_2 != 1) {
             avpriv_request_sample(s, "Non-one track header values");
-            ret = AVERROR_PATCHWELCOME;
-            goto fail;
+            return AVERROR_PATCHWELCOME;
         }
 
         trk->data_offset = avio_tell(s->pb);
@@ -185,15 +182,13 @@  static int pp_bnk_read_header(AVFormatContext *s)
                    i, ctx->track_count);
             break;
         } else if (ret < 0) {
-            goto fail;
+            return ret;
         }
     }
 
     /* File is only a header. */
-    if (ctx->track_count == 0) {
-        ret = AVERROR_INVALIDDATA;
-        goto fail;
-    }
+    if (ctx->track_count == 0)
+        return AVERROR_INVALIDDATA;
 
     ctx->is_music = (hdr.flags & PP_BNK_FLAG_MUSIC) &&
                     (ctx->track_count == 2) &&
@@ -201,10 +196,8 @@  static int pp_bnk_read_header(AVFormatContext *s)
 
     /* Build the streams. */
     for (int i = 0; i < (ctx->is_music ? 1 : ctx->track_count); i++) {
-        if (!(st = avformat_new_stream(s, NULL))) {
-            ret = AVERROR(ENOMEM);
-            goto fail;
-        }
+        if (!(st = avformat_new_stream(s, NULL)))
+            return AVERROR(ENOMEM);
 
         par                         = st->codecpar;
         par->codec_type             = AVMEDIA_TYPE_AUDIO;
@@ -231,10 +224,6 @@  static int pp_bnk_read_header(AVFormatContext *s)
     }
 
     return 0;
-
-fail:
-    av_freep(&ctx->tracks);
-    return ret;
 }
 
 static int pp_bnk_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -336,6 +325,7 @@  const AVInputFormat ff_pp_bnk_demuxer = {
     .name           = "pp_bnk",
     .long_name      = NULL_IF_CONFIG_SMALL("Pro Pinball Series Soundbank"),
     .priv_data_size = sizeof(PPBnkCtx),
+    .flags_internal = FF_FMT_INIT_CLEANUP,
     .read_probe     = pp_bnk_probe,
     .read_header    = pp_bnk_read_header,
     .read_packet    = pp_bnk_read_packet,