diff mbox series

[FFmpeg-devel,05/54] avformat/aaxdec: Simplify cleanup after read_header failure

Message ID HE1PR0301MB215461001FEF5D15C51A74078F309@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
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/aaxdec.c | 83 ++++++++++++++------------------------------
 1 file changed, 27 insertions(+), 56 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/aaxdec.c b/libavformat/aaxdec.c
index 0cbf933dfd..38d57d36c2 100644
--- a/libavformat/aaxdec.c
+++ b/libavformat/aaxdec.c
@@ -150,26 +150,20 @@  static int aax_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
 
     a->xcolumns = av_calloc(a->columns, sizeof(*a->xcolumns));
-    if (!a->xcolumns) {
-        ret = AVERROR(ENOMEM);
-        goto fail;
-    }
+    if (!a->xcolumns)
+        return AVERROR(ENOMEM);
 
     a->string_table = av_calloc(a->strings_size + 1, sizeof(*a->string_table));
-    if (!a->string_table) {
-        ret = AVERROR(ENOMEM);
-        goto fail;
-    }
+    if (!a->string_table)
+        return AVERROR(ENOMEM);
 
     for (int c = 0; c < a->columns; c++) {
         uint8_t info = avio_r8(pb);
         uint32_t offset = avio_rb32(pb);
         int value_size;
 
-        if (offset >= a->strings_size) {
-            ret = AVERROR_INVALIDDATA;
-            goto fail;
-        }
+        if (offset >= a->strings_size)
+            return AVERROR_INVALIDDATA;
 
         a->xcolumns[c].flag = info >>   4;
         a->xcolumns[c].type = info & 0x0F;
@@ -196,8 +190,7 @@  static int aax_read_header(AVFormatContext *s)
             value_size = 0x10;
             break;
         default:
-            ret = AVERROR_INVALIDDATA;
-            goto fail;
+            return AVERROR_INVALIDDATA;
         }
 
         a->xcolumns[c].size = value_size;
@@ -222,9 +215,8 @@  static int aax_read_header(AVFormatContext *s)
     ret = avio_read(pb, a->string_table, a->strings_size);
     if (ret != a->strings_size) {
         if (ret < 0)
-            goto fail;
-        ret = AVERROR(EIO);
-        goto fail;
+            return ret;
+        return AVERROR(EIO);
     }
 
     for (int c = 0; c < a->columns; c++) {
@@ -244,10 +236,8 @@  static int aax_read_header(AVFormatContext *s)
                 data_offset = a->schema_offset + col_offset;
             } else if (flag & COLUMN_FLAG_ROW) {
                 data_offset = a->rows_offset + r * a->row_width + col_offset;
-            } else {
-                ret = AVERROR_INVALIDDATA;
-                goto fail;
-            }
+            } else
+                return AVERROR_INVALIDDATA;
 
             avio_seek(pb, data_offset, SEEK_SET);
             if (type == COLUMN_TYPE_VLDATA) {
@@ -257,23 +247,17 @@  static int aax_read_header(AVFormatContext *s)
                 size  = avio_rb32(pb);
                 a->segments[r].start = start + a->data_offset;
                 a->segments[r].end   = a->segments[r].start + size;
-            } else {
-                ret = AVERROR_INVALIDDATA;
-                goto fail;
-            }
+            } else
+                return AVERROR_INVALIDDATA;
         }
     }
 
-    if (!a->segments[0].end) {
-        ret = AVERROR_INVALIDDATA;
-        goto fail;
-    }
+    if (!a->segments[0].end)
+        return AVERROR_INVALIDDATA;
 
     st = avformat_new_stream(s, NULL);
-    if (!st) {
-        ret = AVERROR(ENOMEM);
-        goto fail;
-    }
+    if (!st)
+        return AVERROR(ENOMEM);
     st->start_time = 0;
     par = s->streams[0]->codecpar;
     par->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -282,42 +266,28 @@  static int aax_read_header(AVFormatContext *s)
     if (!strcmp(codec, "AAX")) {
         par->codec_id = AV_CODEC_ID_ADPCM_ADX;
         avio_seek(pb, a->segments[0].start, SEEK_SET);
-        if (avio_rb16(pb) != 0x8000) {
-            ret = AVERROR_INVALIDDATA;
-            goto fail;
-        }
+        if (avio_rb16(pb) != 0x8000)
+            return AVERROR_INVALIDDATA;
         extradata_size = avio_rb16(pb) + 4;
-        if (extradata_size < 12) {
-            ret = AVERROR_INVALIDDATA;
-            goto fail;
-        }
+        if (extradata_size < 12)
+            return AVERROR_INVALIDDATA;
         avio_seek(pb, -4, SEEK_CUR);
         ret = ff_get_extradata(s, par, pb, extradata_size);
-        if (ret < 0) {
-            goto fail;
-        }
+        if (ret < 0)
+            return ret;
         par->channels    = AV_RB8 (par->extradata + 7);
         par->sample_rate = AV_RB32(par->extradata + 8);
-        if (!par->channels || !par->sample_rate) {
-            ret = AVERROR_INVALIDDATA;
-            goto fail;
-        }
+        if (!par->channels || !par->sample_rate)
+            return AVERROR_INVALIDDATA;
 
         avpriv_set_pts_info(st, 64, 32, par->sample_rate);
   /*} else if (!strcmp(codec, "HCA") ){
         par->codec_id = AV_CODEC_ID_HCA;*/
     } else {
-        ret = AVERROR_INVALIDDATA;
-        goto fail;
+        return AVERROR_INVALIDDATA;
     }
 
     return 0;
-fail:
-    av_freep(&a->string_table);
-    av_freep(&a->xcolumns);
-    av_freep(&a->segments);
-
-    return ret;
 }
 
 static int aax_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -406,6 +376,7 @@  const AVInputFormat ff_aax_demuxer = {
     .name           = "aax",
     .long_name      = NULL_IF_CONFIG_SMALL("CRI AAX"),
     .priv_data_size = sizeof(AAXContext),
+    .flags_internal = FF_FMT_INIT_CLEANUP,
     .read_probe     = aax_probe,
     .read_header    = aax_read_header,
     .read_packet    = aax_read_packet,