[FFmpeg-cvslog] avformat/ape: Simplify cleanup after read_header failure

Andreas Rheinhardt git at videolan.org
Thu Jul 8 16:44:08 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sat Mar 21 18:31:06 2020 +0100| [58da6b18a3d2f11b0f7a1bb80beda19cdf267431] | committer: Andreas Rheinhardt

avformat/ape: Simplify cleanup after read_header failure

by setting the FF_FMT_INIT_CLEANUP flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

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

 libavformat/ape.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

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,



More information about the ffmpeg-cvslog mailing list