aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/avidec.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2020-03-21 18:31:06 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-07-07 21:23:13 +0200
commit609672a4a3344b511204a490c817c67ba99b3c79 (patch)
tree671089cabb42149e7b4546bddcc21f91d42f1041 /libavformat/avidec.c
parent822be438491ec9cf724c5b04d6f844ac7b188b8c (diff)
downloadffmpeg-609672a4a3344b511204a490c817c67ba99b3c79.tar.gz
avformat/avidec: 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/avidec.c')
-rw-r--r--libavformat/avidec.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 14a2dd6cd7..39039f5bc9 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -122,7 +122,6 @@ static const AVMetadataConv avi_metadata_conv[] = {
{ 0 },
};
-static int avi_read_close(AVFormatContext *s);
static int avi_load_index(AVFormatContext *s);
static int guess_ni_flag(AVFormatContext *s);
@@ -474,7 +473,6 @@ static int calculate_bitrate(AVFormatContext *s)
return 1;
}
-#define RETURN_ERROR(code) do { ret = (code); goto fail; } while (0)
static int avi_read_header(AVFormatContext *s)
{
AVIContext *avi = s->priv_data;
@@ -510,7 +508,7 @@ static int avi_read_header(AVFormatContext *s)
frame_period = 0;
for (;;) {
if (avio_feof(pb))
- RETURN_ERROR(AVERROR_INVALIDDATA);
+ return AVERROR_INVALIDDATA;
tag = avio_rl32(pb);
size = avio_rl32(pb);
@@ -582,12 +580,12 @@ static int avi_read_header(AVFormatContext *s)
stream_index++;
st = avformat_new_stream(s, NULL);
if (!st)
- RETURN_ERROR(AVERROR(ENOMEM));
+ return AVERROR(ENOMEM);
st->id = stream_index;
ast = av_mallocz(sizeof(AVIStream));
if (!ast)
- RETURN_ERROR(AVERROR(ENOMEM));
+ return AVERROR(ENOMEM);
st->priv_data = ast;
}
if (amv_file_format)
@@ -603,7 +601,7 @@ static int avi_read_header(AVFormatContext *s)
/* After some consideration -- I don't think we
* have to support anything but DV in type1 AVIs. */
if (s->nb_streams != 1)
- RETURN_ERROR(AVERROR_INVALIDDATA);
+ return AVERROR_INVALIDDATA;
if (handler != MKTAG('d', 'v', 's', 'd') &&
handler != MKTAG('d', 'v', 'h', 'd') &&
@@ -708,7 +706,7 @@ static int avi_read_header(AVFormatContext *s)
"Invalid sample_size %d at stream %d\n",
ast->sample_size,
stream_index);
- RETURN_ERROR(AVERROR_INVALIDDATA);
+ return AVERROR_INVALIDDATA;
}
av_log(s, AV_LOG_WARNING,
"Invalid sample_size %d at stream %d "
@@ -944,7 +942,7 @@ static int avi_read_header(AVFormatContext *s)
av_log(s, AV_LOG_WARNING, "New extradata in strd chunk, freeing previous one.\n");
}
if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0)
- goto fail;
+ return ret;
}
if (st->codecpar->extradata_size & 1) //FIXME check if the encoder really did this correctly
@@ -962,7 +960,7 @@ static int avi_read_header(AVFormatContext *s)
avi->use_odml &&
read_odml_index(s, 0) < 0 &&
(s->error_recognition & AV_EF_EXPLODE))
- RETURN_ERROR(AVERROR_INVALIDDATA);
+ return AVERROR_INVALIDDATA;
avio_seek(pb, pos + size, SEEK_SET);
break;
case MKTAG('v', 'p', 'r', 'p'):
@@ -1005,7 +1003,7 @@ static int avi_read_header(AVFormatContext *s)
if (s->nb_streams) {
ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size);
if (ret < 0)
- goto fail;
+ return ret;
break;
}
default:
@@ -1016,7 +1014,7 @@ static int avi_read_header(AVFormatContext *s)
"I will ignore it and try to continue anyway.\n",
av_fourcc2str(tag), size);
if (s->error_recognition & AV_EF_EXPLODE)
- RETURN_ERROR(AVERROR_INVALIDDATA);
+ return AVERROR_INVALIDDATA;
avi->movi_list = avio_tell(pb) - 4;
avi->movi_end = avi->fsize;
goto end_of_header;
@@ -1032,9 +1030,8 @@ static int avi_read_header(AVFormatContext *s)
end_of_header:
/* check stream number */
- if (stream_index != s->nb_streams - 1) {
- RETURN_ERROR(AVERROR_INVALIDDATA);
- }
+ if (stream_index != s->nb_streams - 1)
+ return AVERROR_INVALIDDATA;
if (!avi->index_loaded && (pb->seekable & AVIO_SEEKABLE_NORMAL))
avi_load_index(s);
@@ -1042,7 +1039,7 @@ end_of_header:
avi->index_loaded |= 1;
if ((ret = guess_ni_flag(s)) < 0)
- goto fail;
+ return ret;
avi->non_interleaved |= ret | (s->flags & AVFMT_FLAG_SORT_DTS);
@@ -1079,9 +1076,6 @@ end_of_header:
ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv);
return 0;
-fail:
- avi_read_close(s);
- return ret;
}
static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt)
@@ -1971,6 +1965,7 @@ const AVInputFormat ff_avi_demuxer = {
.name = "avi",
.long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
.priv_data_size = sizeof(AVIContext),
+ .flags_internal = FF_FMT_INIT_CLEANUP,
.extensions = "avi",
.read_probe = avi_probe,
.read_header = avi_read_header,