diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-09-19 06:32:42 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2021-02-27 07:20:59 +0100 |
commit | ee0bf1d5f8794423dc3086c39b7e22ded65d5f31 (patch) | |
tree | 1933e591fd8849069a43e2644858ca7ce96820e2 /libavformat/dashdec.c | |
parent | 74b97ea6034c75044c43b065df1fc07e5b2e4b84 (diff) | |
download | ffmpeg-ee0bf1d5f8794423dc3086c39b7e22ded65d5f31.tar.gz |
avformat/dashdec: Fix leak of string on error when parsing representation
The DASH demuxer currently extracts several strings at once from an xml
document before processing them one by one; these strings are allocated,
stored in local variables and need to be freed by the demuxer itself.
So if an error happens when processing one of them, all strings need to
be freed before returning. This has simply not been done, leading to
leaks.
A simple fix would be to add the necessary code for freeing; yet there is
a better solution: Avoid having several strings at the same time by
extracting a string, processing it and immediately freeing it. That way
one only has to free at most one string on error.
Reviewed-by: Steven Liu <lq@chinaffmpeg.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
(cherry picked from commit e7aea1fe7304352c4b5359159700ab4957b10449)
Diffstat (limited to 'libavformat/dashdec.c')
-rw-r--r-- | libavformat/dashdec.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 5ed55687b7..5b1ade094f 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -897,46 +897,45 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, fragment_templates_tab[3] = period_segmenttemplate_node; fragment_templates_tab[4] = period_segmentlist_node; - presentation_timeoffset_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "presentationTimeOffset"); - duration_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "duration"); - startnumber_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "startNumber"); - timescale_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "timescale"); initialization_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "initialization"); - media_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "media"); - if (initialization_val) { rep->init_section = av_mallocz(sizeof(struct fragment)); - if (!rep->init_section) + if (!rep->init_section) { + xmlFree(initialization_val); goto enomem; + } c->max_url_size = aligned(c->max_url_size + strlen(initialization_val)); rep->init_section->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, initialization_val); + xmlFree(initialization_val); if (!rep->init_section->url) goto enomem; rep->init_section->size = -1; - xmlFree(initialization_val); } - + media_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "media"); if (media_val) { c->max_url_size = aligned(c->max_url_size + strlen(media_val)); rep->url_template = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, media_val); xmlFree(media_val); } - + presentation_timeoffset_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "presentationTimeOffset"); if (presentation_timeoffset_val) { rep->presentation_timeoffset = (int64_t) strtoll(presentation_timeoffset_val, NULL, 10); av_log(s, AV_LOG_TRACE, "rep->presentation_timeoffset = [%"PRId64"]\n", rep->presentation_timeoffset); xmlFree(presentation_timeoffset_val); } + duration_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "duration"); if (duration_val) { rep->fragment_duration = (int64_t) strtoll(duration_val, NULL, 10); av_log(s, AV_LOG_TRACE, "rep->fragment_duration = [%"PRId64"]\n", rep->fragment_duration); xmlFree(duration_val); } + timescale_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "timescale"); if (timescale_val) { rep->fragment_timescale = (int64_t) strtoll(timescale_val, NULL, 10); av_log(s, AV_LOG_TRACE, "rep->fragment_timescale = [%"PRId64"]\n", rep->fragment_timescale); xmlFree(timescale_val); } + startnumber_val = get_val_from_nodes_tab(fragment_templates_tab, 4, "startNumber"); if (startnumber_val) { rep->start_number = rep->first_seq_no = (int64_t) strtoll(startnumber_val, NULL, 10); av_log(s, AV_LOG_TRACE, "rep->first_seq_no = [%"PRId64"]\n", rep->first_seq_no); |