[FFmpeg-devel] [PATCH 21/54] avformat/matroskadec: Simplify cleanup after read_header failure
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Wed Jun 16 02:32:10 EEST 2021
by setting the FF_FMT_INIT_CLEANUP flag.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
libavformat/matroskadec.c | 29 ++++++++++-------------------
1 file changed, 10 insertions(+), 19 deletions(-)
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 356a02339c..10c1641eb7 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -796,8 +796,6 @@ static const CodecMime mkv_mime_tags[] = {
static const char *const matroska_doctypes[] = { "matroska", "webm" };
-static int matroska_read_close(AVFormatContext *s);
-
/*
* This function prepares the status for parsing of level 1 elements.
*/
@@ -2952,11 +2950,11 @@ static int matroska_read_header(AVFormatContext *s)
while (res != 1) {
res = matroska_resync(matroska, pos);
if (res < 0)
- goto fail;
+ return res;
pos = avio_tell(matroska->ctx->pb);
res = ebml_parse(matroska, matroska_segment, matroska);
if (res == AVERROR(EIO)) // EOF is translated to EIO, this exists the loop on EOF
- goto fail;
+ return res;
}
/* Set data_offset as it might be needed later by seek_frame_generic. */
if (matroska->current_id == MATROSKA_ID_CLUSTER)
@@ -2976,7 +2974,7 @@ static int matroska_read_header(AVFormatContext *s)
res = matroska_parse_tracks(s);
if (res < 0)
- goto fail;
+ return res;
attachments = attachments_list->elem;
for (j = 0; j < attachments_list->nb_elem; j++) {
@@ -3005,7 +3003,7 @@ static int matroska_read_header(AVFormatContext *s)
if (st->codecpar->codec_id != AV_CODEC_ID_NONE) {
res = ff_add_attached_pic(s, st, NULL, &attachments[j].bin.buf, 0);
if (res < 0)
- goto fail;
+ return res;
} else {
st->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT;
if (ff_alloc_extradata(st->codecpar, attachments[j].bin.size))
@@ -3040,9 +3038,6 @@ static int matroska_read_header(AVFormatContext *s)
matroska_convert_tags(s);
return 0;
-fail:
- matroska_read_close(s);
- return res;
}
/*
@@ -4236,16 +4231,13 @@ static int webm_dash_manifest_read_header(AVFormatContext *s)
}
if (!matroska->tracks.nb_elem || !s->nb_streams) {
av_log(s, AV_LOG_ERROR, "No track found\n");
- ret = AVERROR_INVALIDDATA;
- goto fail;
+ return AVERROR_INVALIDDATA;
}
if (!matroska->is_live) {
buf = av_asprintf("%g", matroska->duration);
- if (!buf) {
- ret = AVERROR(ENOMEM);
- goto fail;
- }
+ if (!buf)
+ return AVERROR(ENOMEM);
av_dict_set(&s->streams[0]->metadata, DURATION,
buf, AV_DICT_DONT_STRDUP_VAL);
@@ -4268,7 +4260,7 @@ static int webm_dash_manifest_read_header(AVFormatContext *s)
ret = webm_dash_manifest_cues(s, init_range);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Error parsing Cues\n");
- goto fail;
+ return ret;
}
}
@@ -4278,9 +4270,6 @@ static int webm_dash_manifest_read_header(AVFormatContext *s)
matroska->bandwidth, 0);
}
return 0;
-fail:
- matroska_read_close(s);
- return ret;
}
static int webm_dash_manifest_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -4307,6 +4296,7 @@ const AVInputFormat ff_matroska_demuxer = {
.long_name = NULL_IF_CONFIG_SMALL("Matroska / WebM"),
.extensions = "mkv,mk3d,mka,mks,webm",
.priv_data_size = sizeof(MatroskaDemuxContext),
+ .flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = matroska_probe,
.read_header = matroska_read_header,
.read_packet = matroska_read_packet,
@@ -4319,6 +4309,7 @@ const AVInputFormat ff_webm_dash_manifest_demuxer = {
.name = "webm_dash_manifest",
.long_name = NULL_IF_CONFIG_SMALL("WebM DASH Manifest"),
.priv_data_size = sizeof(MatroskaDemuxContext),
+ .flags_internal = FF_FMT_INIT_CLEANUP,
.read_header = webm_dash_manifest_read_header,
.read_packet = webm_dash_manifest_read_packet,
.read_close = matroska_read_close,
--
2.27.0
More information about the ffmpeg-devel
mailing list