1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-01-24 13:56:33 +02:00

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>
This commit is contained in:
Andreas Rheinhardt 2020-03-21 18:31:06 +01:00
parent 822be43849
commit 609672a4a3

View File

@ -122,7 +122,6 @@ static const AVMetadataConv avi_metadata_conv[] = {
{ 0 }, { 0 },
}; };
static int avi_read_close(AVFormatContext *s);
static int avi_load_index(AVFormatContext *s); static int avi_load_index(AVFormatContext *s);
static int guess_ni_flag(AVFormatContext *s); static int guess_ni_flag(AVFormatContext *s);
@ -474,7 +473,6 @@ static int calculate_bitrate(AVFormatContext *s)
return 1; return 1;
} }
#define RETURN_ERROR(code) do { ret = (code); goto fail; } while (0)
static int avi_read_header(AVFormatContext *s) static int avi_read_header(AVFormatContext *s)
{ {
AVIContext *avi = s->priv_data; AVIContext *avi = s->priv_data;
@ -510,7 +508,7 @@ static int avi_read_header(AVFormatContext *s)
frame_period = 0; frame_period = 0;
for (;;) { for (;;) {
if (avio_feof(pb)) if (avio_feof(pb))
RETURN_ERROR(AVERROR_INVALIDDATA); return AVERROR_INVALIDDATA;
tag = avio_rl32(pb); tag = avio_rl32(pb);
size = avio_rl32(pb); size = avio_rl32(pb);
@ -582,12 +580,12 @@ static int avi_read_header(AVFormatContext *s)
stream_index++; stream_index++;
st = avformat_new_stream(s, NULL); st = avformat_new_stream(s, NULL);
if (!st) if (!st)
RETURN_ERROR(AVERROR(ENOMEM)); return AVERROR(ENOMEM);
st->id = stream_index; st->id = stream_index;
ast = av_mallocz(sizeof(AVIStream)); ast = av_mallocz(sizeof(AVIStream));
if (!ast) if (!ast)
RETURN_ERROR(AVERROR(ENOMEM)); return AVERROR(ENOMEM);
st->priv_data = ast; st->priv_data = ast;
} }
if (amv_file_format) if (amv_file_format)
@ -603,7 +601,7 @@ static int avi_read_header(AVFormatContext *s)
/* After some consideration -- I don't think we /* After some consideration -- I don't think we
* have to support anything but DV in type1 AVIs. */ * have to support anything but DV in type1 AVIs. */
if (s->nb_streams != 1) if (s->nb_streams != 1)
RETURN_ERROR(AVERROR_INVALIDDATA); return AVERROR_INVALIDDATA;
if (handler != MKTAG('d', 'v', 's', 'd') && if (handler != MKTAG('d', 'v', 's', 'd') &&
handler != MKTAG('d', 'v', 'h', '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", "Invalid sample_size %d at stream %d\n",
ast->sample_size, ast->sample_size,
stream_index); stream_index);
RETURN_ERROR(AVERROR_INVALIDDATA); return AVERROR_INVALIDDATA;
} }
av_log(s, AV_LOG_WARNING, av_log(s, AV_LOG_WARNING,
"Invalid sample_size %d at stream %d " "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"); 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) 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 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 && avi->use_odml &&
read_odml_index(s, 0) < 0 && read_odml_index(s, 0) < 0 &&
(s->error_recognition & AV_EF_EXPLODE)) (s->error_recognition & AV_EF_EXPLODE))
RETURN_ERROR(AVERROR_INVALIDDATA); return AVERROR_INVALIDDATA;
avio_seek(pb, pos + size, SEEK_SET); avio_seek(pb, pos + size, SEEK_SET);
break; break;
case MKTAG('v', 'p', 'r', 'p'): case MKTAG('v', 'p', 'r', 'p'):
@ -1005,7 +1003,7 @@ static int avi_read_header(AVFormatContext *s)
if (s->nb_streams) { if (s->nb_streams) {
ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size); ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size);
if (ret < 0) if (ret < 0)
goto fail; return ret;
break; break;
} }
default: default:
@ -1016,7 +1014,7 @@ static int avi_read_header(AVFormatContext *s)
"I will ignore it and try to continue anyway.\n", "I will ignore it and try to continue anyway.\n",
av_fourcc2str(tag), size); av_fourcc2str(tag), size);
if (s->error_recognition & AV_EF_EXPLODE) if (s->error_recognition & AV_EF_EXPLODE)
RETURN_ERROR(AVERROR_INVALIDDATA); return AVERROR_INVALIDDATA;
avi->movi_list = avio_tell(pb) - 4; avi->movi_list = avio_tell(pb) - 4;
avi->movi_end = avi->fsize; avi->movi_end = avi->fsize;
goto end_of_header; goto end_of_header;
@ -1032,9 +1030,8 @@ static int avi_read_header(AVFormatContext *s)
end_of_header: end_of_header:
/* check stream number */ /* check stream number */
if (stream_index != s->nb_streams - 1) { if (stream_index != s->nb_streams - 1)
RETURN_ERROR(AVERROR_INVALIDDATA); return AVERROR_INVALIDDATA;
}
if (!avi->index_loaded && (pb->seekable & AVIO_SEEKABLE_NORMAL)) if (!avi->index_loaded && (pb->seekable & AVIO_SEEKABLE_NORMAL))
avi_load_index(s); avi_load_index(s);
@ -1042,7 +1039,7 @@ end_of_header:
avi->index_loaded |= 1; avi->index_loaded |= 1;
if ((ret = guess_ni_flag(s)) < 0) if ((ret = guess_ni_flag(s)) < 0)
goto fail; return ret;
avi->non_interleaved |= ret | (s->flags & AVFMT_FLAG_SORT_DTS); 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); ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv);
return 0; return 0;
fail:
avi_read_close(s);
return ret;
} }
static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt) static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt)
@ -1971,6 +1965,7 @@ const AVInputFormat ff_avi_demuxer = {
.name = "avi", .name = "avi",
.long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"), .long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
.priv_data_size = sizeof(AVIContext), .priv_data_size = sizeof(AVIContext),
.flags_internal = FF_FMT_INIT_CLEANUP,
.extensions = "avi", .extensions = "avi",
.read_probe = avi_probe, .read_probe = avi_probe,
.read_header = avi_read_header, .read_header = avi_read_header,