@@ -749,8 +749,6 @@ static EbmlSyntax matroska_cluster_enter[] = {
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.
*/
@@ -2837,7 +2835,7 @@ 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);
}
@@ -2859,7 +2857,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++) {
@@ -2937,9 +2935,6 @@ static int matroska_read_header(AVFormatContext *s)
matroska_convert_tags(s);
return 0;
-fail:
- matroska_read_close(s);
- return res;
}
/*
@@ -4129,7 +4124,6 @@ static int webm_dash_manifest_read_header(AVFormatContext *s)
return -1;
}
if (!s->nb_streams) {
- matroska_read_close(s);
av_log(s, AV_LOG_ERROR, "No streams found\n");
return AVERROR_INVALIDDATA;
}
@@ -4200,7 +4194,8 @@ AVInputFormat ff_matroska_demuxer = {
.read_packet = matroska_read_packet,
.read_close = matroska_read_close,
.read_seek = matroska_read_seek,
- .mime_type = "audio/webm,audio/x-matroska,video/webm,video/x-matroska"
+ .mime_type = "audio/webm,audio/x-matroska,video/webm,video/x-matroska",
+ .flags_internal = FF_INPUTFORMAT_HEADER_CLEANUP,
};
AVInputFormat ff_webm_dash_manifest_demuxer = {
@@ -4211,4 +4206,5 @@ AVInputFormat ff_webm_dash_manifest_demuxer = {
.read_packet = webm_dash_manifest_read_packet,
.read_close = matroska_read_close,
.priv_class = &webm_dash_class,
+ .flags_internal = FF_INPUTFORMAT_HEADER_CLEANUP,
};
This commit simplifies cleanup after read_header failure: By setting the FF_INPUTFORMAT_HEADER_CLEANUP flag for both the ordinary Matroska demuxer as well as the WebM DASH Manifest demuxer one can remove the "goto fail" in matroska_read_header() as well as an explicit matroska_read_close() in webm_dash_manifest_read_header(); the forward declaration of matroska_read_close() can also be removed. For the Matroska demuxer this fixes a memleak when adding an attached picture fails; for the WebM DASH Manifest demuxer this fixes memleaks because calling matroska_read_close() has been forgotten on several error paths. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> --- libavformat/matroskadec.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)