diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2020-03-21 18:31:06 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-07-07 22:13:06 +0200 |
commit | 7a1037b6bd4adf3fd3f382a0b2306048b2050a05 (patch) | |
tree | cbac002572161be8e2ed1ec7f9ac3d4e7eb9d208 /libavformat/icodec.c | |
parent | 0a7e9111086e2321aa2b965f8cc7118054733c73 (diff) | |
download | ffmpeg-7a1037b6bd4adf3fd3f382a0b2306048b2050a05.tar.gz |
avformat/icodec: Simplify cleanup after read_header failure
by setting the FF_FMT_INIT_CLEANUP flag.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/icodec.c')
-rw-r--r-- | libavformat/icodec.c | 21 |
1 files changed, 8 insertions, 13 deletions
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, |