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

Andreas Rheinhardt git at videolan.org
Thu Jul 8 16:45:13 EEST 2021


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

avformat/rmdec: 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=48de45ea59101b9ea2818bd62a628ec734e81b41
---

 libavformat/rmdec.c | 56 +++++++++++++++++++----------------------------------
 1 file changed, 20 insertions(+), 36 deletions(-)

diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index ce27bd2299..2529e8b1a1 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -66,8 +66,6 @@ typedef struct RMDemuxContext {
     int data_end;
 } RMDemuxContext;
 
-static int rm_read_close(AVFormatContext *s);
-
 static inline void get_strl(AVIOContext *pb, char *buf, int buf_size, int len)
 {
     int read = avio_get_str(pb, len, buf, buf_size);
@@ -563,16 +561,15 @@ static int rm_read_header(AVFormatContext *s)
     avio_skip(pb, tag_size - 8);
 
     for(;;) {
-        ret = AVERROR_INVALIDDATA;
         if (avio_feof(pb))
-            goto fail;
+            return AVERROR_INVALIDDATA;
         tag = avio_rl32(pb);
         tag_size = avio_rb32(pb);
         avio_rb16(pb);
         av_log(s, AV_LOG_TRACE, "tag=%s size=%d\n",
                av_fourcc2str(tag), tag_size);
         if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
-            goto fail;
+            return AVERROR_INVALIDDATA;
         switch(tag) {
         case MKTAG('P', 'R', 'O', 'P'):
             /* file header */
@@ -594,10 +591,8 @@ static int rm_read_header(AVFormatContext *s)
             break;
         case MKTAG('M', 'D', 'P', 'R'):
             st = avformat_new_stream(s, NULL);
-            if (!st) {
-                ret = AVERROR(ENOMEM);
-                goto fail;
-            }
+            if (!st)
+                return AVERROR(ENOMEM);
             st->id = avio_rb16(pb);
             avio_rb32(pb); /* max bit rate */
             st->codecpar->bit_rate = avio_rb32(pb); /* bit rate */
@@ -614,10 +609,8 @@ static int rm_read_header(AVFormatContext *s)
             get_str8(pb, mime, sizeof(mime)); /* mimetype */
             st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
             st->priv_data = ff_rm_alloc_rmstream();
-            if (!st->priv_data) {
-                ret = AVERROR(ENOMEM);
-                goto fail;
-            }
+            if (!st->priv_data)
+                return AVERROR(ENOMEM);
 
             size = avio_rb32(pb);
             codec_pos = avio_tell(pb);
@@ -627,14 +620,14 @@ static int rm_read_header(AVFormatContext *s)
             if (v == MKBETAG('M', 'L', 'T', 'I')) {
                 ret = rm_read_multi(s, s->pb, st, mime);
                 if (ret < 0)
-                    goto fail;
+                    return ret;
                 avio_seek(pb, codec_pos + size, SEEK_SET);
             } else {
                 avio_skip(pb, -4);
                 ret = ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data,
                                                 size, mime);
                 if (ret < 0)
-                    goto fail;
+                    return ret;
             }
 
             break;
@@ -662,10 +655,6 @@ static int rm_read_header(AVFormatContext *s)
     }
 
     return 0;
-
-fail:
-    rm_read_close(s);
-    return ret;
 }
 
 static int get_num(AVIOContext *pb, int *len)
@@ -1153,6 +1142,7 @@ const AVInputFormat ff_rm_demuxer = {
     .name           = "rm",
     .long_name      = NULL_IF_CONFIG_SMALL("RealMedia"),
     .priv_data_size = sizeof(RMDemuxContext),
+    .flags_internal = FF_FMT_INIT_CLEANUP,
     .read_probe     = rm_probe,
     .read_header    = rm_read_header,
     .read_packet    = rm_read_packet,
@@ -1254,18 +1244,16 @@ static int ivr_read_header(AVFormatContext *s)
 
     for (n = 0; n < nb_streams; n++) {
         if (!(st = avformat_new_stream(s, NULL)) ||
-            !(st->priv_data = ff_rm_alloc_rmstream())) {
-            ret = AVERROR(ENOMEM);
-            goto fail;
-        }
+            !(st->priv_data = ff_rm_alloc_rmstream()))
+            return AVERROR(ENOMEM);
 
         if (avio_r8(pb) != 1)
-            goto invalid_data;
+            return AVERROR_INVALIDDATA;
 
         count = avio_rb32(pb);
         for (i = 0; i < count; i++) {
             if (avio_feof(pb))
-                goto invalid_data;
+                return AVERROR_INVALIDDATA;
 
             type = avio_r8(pb);
             tlen  = avio_rb32(pb);
@@ -1277,25 +1265,25 @@ static int ivr_read_header(AVFormatContext *s)
             } else if (type == 4 && !strncmp(key, "OpaqueData", tlen)) {
                 ret = ffio_ensure_seekback(pb, 4);
                 if (ret < 0)
-                    goto fail;
+                    return ret;
                 if (avio_rb32(pb) == MKBETAG('M', 'L', 'T', 'I')) {
                     ret = rm_read_multi(s, pb, st, NULL);
                 } else {
                     if (avio_feof(pb))
-                        goto invalid_data;
+                        return AVERROR_INVALIDDATA;
                     avio_seek(pb, -4, SEEK_CUR);
                     ret = ff_rm_read_mdpr_codecdata(s, pb, st, st->priv_data, len, NULL);
                 }
 
                 if (ret < 0)
-                    goto fail;
+                    return ret;
             } else if (type == 4) {
                 int j;
 
                 av_log(s, AV_LOG_DEBUG, "%s = '0x", key);
                 for (j = 0; j < len; j++) {
                     if (avio_feof(pb))
-                        goto invalid_data;
+                        return AVERROR_INVALIDDATA;
                     av_log(s, AV_LOG_DEBUG, "%X", avio_r8(pb));
                 }
                 av_log(s, AV_LOG_DEBUG, "'\n");
@@ -1312,19 +1300,14 @@ static int ivr_read_header(AVFormatContext *s)
     }
 
     if (avio_r8(pb) != 6)
-        goto invalid_data;
+        return AVERROR_INVALIDDATA;
     avio_skip(pb, 12);
     avio_seek(pb, avio_rb64(pb) + pos, SEEK_SET);
     if (avio_r8(pb) != 8)
-        goto invalid_data;
+        return AVERROR_INVALIDDATA;
     avio_skip(pb, 8);
 
     return 0;
-invalid_data:
-    ret = AVERROR_INVALIDDATA;
-fail:
-    rm_read_close(s);
-    return ret;
 }
 
 static int ivr_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -1412,6 +1395,7 @@ const AVInputFormat ff_ivr_demuxer = {
     .name           = "ivr",
     .long_name      = NULL_IF_CONFIG_SMALL("IVR (Internet Video Recording)"),
     .priv_data_size = sizeof(RMDemuxContext),
+    .flags_internal = FF_FMT_INIT_CLEANUP,
     .read_probe     = ivr_probe,
     .read_header    = ivr_read_header,
     .read_packet    = ivr_read_packet,



More information about the ffmpeg-cvslog mailing list