diff mbox series

[FFmpeg-devel,07/54] avformat/ape: Simplify cleanup after read_header failure

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

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:31 p.m. UTC
by setting the FF_FMT_INIT_CLEANUP flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/ape.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/ape.c b/libavformat/ape.c
index a4cfd01807..b6f9be4dbc 100644
--- a/libavformat/ape.c
+++ b/libavformat/ape.c
@@ -79,8 +79,6 @@  typedef struct APEContext {
     uint32_t samplerate;
 } APEContext;
 
-static int ape_read_close(AVFormatContext * s);
-
 static int ape_probe(const AVProbeData * p)
 {
     int version = AV_RL16(p->buf+4);
@@ -276,8 +274,7 @@  static int ape_read_header(AVFormatContext * s)
 
         if (pb->eof_reached) {
             av_log(s, AV_LOG_ERROR, "seektable truncated\n");
-            ret = AVERROR_INVALIDDATA;
-            goto fail;
+            return AVERROR_INVALIDDATA;
         }
         ff_dlog(s, "seektable: %8d   %"PRIu32"\n", i, seektable_entry);
     }
@@ -313,8 +310,7 @@  static int ape_read_header(AVFormatContext * s)
             ff_dlog(s, "bittable: %2d\n", bits);
             if (pb->eof_reached) {
                 av_log(s, AV_LOG_ERROR, "bittable truncated\n");
-                ret = AVERROR_INVALIDDATA;
-                goto fail;
+                return AVERROR_INVALIDDATA;
             }
         }
     }
@@ -327,10 +323,8 @@  static int ape_read_header(AVFormatContext * s)
 
     /* now we are ready: build format streams */
     st = avformat_new_stream(s, NULL);
-    if (!st) {
-        ret = AVERROR(ENOMEM);
-        goto fail;
-    }
+    if (!st)
+        return AVERROR(ENOMEM);
 
     total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks;
 
@@ -347,7 +341,7 @@  static int ape_read_header(AVFormatContext * s)
     avpriv_set_pts_info(st, 64, 1, ape->samplerate);
 
     if ((ret = ff_alloc_extradata(st->codecpar, APE_EXTRADATA_SIZE)) < 0)
-        goto fail;
+        return ret;
     AV_WL16(st->codecpar->extradata + 0, ape->fileversion);
     AV_WL16(st->codecpar->extradata + 2, ape->compressiontype);
     AV_WL16(st->codecpar->extradata + 4, ape->formatflags);
@@ -366,10 +360,6 @@  static int ape_read_header(AVFormatContext * s)
     }
 
     return 0;
-fail:
-    ape_read_close(s);
-
-    return ret;
 }
 
 static int ape_read_packet(AVFormatContext * s, AVPacket * pkt)
@@ -454,6 +444,7 @@  const AVInputFormat ff_ape_demuxer = {
     .name           = "ape",
     .long_name      = NULL_IF_CONFIG_SMALL("Monkey's Audio"),
     .priv_data_size = sizeof(APEContext),
+    .flags_internal = FF_FMT_INIT_CLEANUP,
     .read_probe     = ape_probe,
     .read_header    = ape_read_header,
     .read_packet    = ape_read_packet,