diff mbox series

[FFmpeg-devel,15/54] avformat/icodec: Simplify cleanup after read_header failure

Message ID HE1PR0301MB2154F81328D26095ACE3A9068F309@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 7a1037b6bd4adf3fd3f382a0b2306048b2050a05
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/icodec.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/icodec.c b/libavformat/icodec.c
index 9349582ffc..2e677c78f1 100644
--- a/libavformat/icodec.c
+++ b/libavformat/icodec.c
@@ -96,13 +96,11 @@  static int read_header(AVFormatContext *s)
         int tmp;
 
         if (avio_seek(pb, 6 + i * 16, SEEK_SET) < 0)
-            goto fail;
+            return AVERROR_INVALIDDATA;
 
         st = avformat_new_stream(s, NULL);
-        if (!st) {
-            av_freep(&ico->images);
+        if (!st)
             return AVERROR(ENOMEM);
-        }
 
         st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
         st->codecpar->width      = avio_r8(pb);
@@ -116,12 +114,12 @@  static int read_header(AVFormatContext *s)
         ico->images[i].size   = avio_rl32(pb);
         if (ico->images[i].size <= 0) {
             av_log(s, AV_LOG_ERROR, "Invalid image size %d\n", ico->images[i].size);
-            goto fail;
+            return AVERROR_INVALIDDATA;
         }
         ico->images[i].offset = avio_rl32(pb);
 
         if (avio_seek(pb, ico->images[i].offset, SEEK_SET) < 0)
-            goto fail;
+            return AVERROR_INVALIDDATA;
 
         codec = avio_rl32(pb);
         switch (codec) {
@@ -131,9 +129,8 @@  static int read_header(AVFormatContext *s)
             st->codecpar->height   = 0;
             break;
         case 40:
-            if (ico->images[i].size < 40) {
-                goto fail;
-            }
+            if (ico->images[i].size < 40)
+                return AVERROR_INVALIDDATA;
             st->codecpar->codec_id = AV_CODEC_ID_BMP;
             tmp = avio_rl32(pb);
             if (tmp)
@@ -144,14 +141,11 @@  static int read_header(AVFormatContext *s)
             break;
         default:
             avpriv_request_sample(s, "codec %d", codec);
-            goto fail;
+            return AVERROR_INVALIDDATA;
         }
     }
 
     return 0;
-fail:
-    av_freep(&ico->images);
-    return AVERROR_INVALIDDATA;
 }
 
 static int read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -224,6 +218,7 @@  const AVInputFormat ff_ico_demuxer = {
     .name           = "ico",
     .long_name      = NULL_IF_CONFIG_SMALL("Microsoft Windows ICO"),
     .priv_data_size = sizeof(IcoDemuxContext),
+    .flags_internal = FF_FMT_INIT_CLEANUP,
     .read_probe     = probe,
     .read_header    = read_header,
     .read_packet    = read_packet,