avformat/hlsenc: Fix memleaks with repeating parameters

When a parameter like e.g. language is contained more than once in the
part of var_stream_map pertaining to a single VariantStream, the later
one just overwrites the pointer to the earlier one, leading to a
memleak. This commit changes this by handling the situation gracefully:
The earlier string is silently freed first, so that the last one wins.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Steven Liu <lq@onvideo.cn>
This commit is contained in:
Andreas Rheinhardt 2019-12-16 01:04:13 +01:00 committed by Steven Liu
parent 53c1458bf2
commit 5ba3a8958c

View File

@ -1937,6 +1937,7 @@ static int parse_variant_stream_mapstring(AVFormatContext *s)
while (keyval = av_strtok(varstr, ",", &saveptr2)) { while (keyval = av_strtok(varstr, ",", &saveptr2)) {
varstr = NULL; varstr = NULL;
if (av_strstart(keyval, "language:", &val)) { if (av_strstart(keyval, "language:", &val)) {
av_free(vs->language);
vs->language = av_strdup(val); vs->language = av_strdup(val);
if (!vs->language) if (!vs->language)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -1947,16 +1948,19 @@ static int parse_variant_stream_mapstring(AVFormatContext *s)
hls->has_default_key = 1; hls->has_default_key = 1;
continue; continue;
} else if (av_strstart(keyval, "name:", &val)) { } else if (av_strstart(keyval, "name:", &val)) {
av_free(vs->varname);
vs->varname = av_strdup(val); vs->varname = av_strdup(val);
if (!vs->varname) if (!vs->varname)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
continue; continue;
} else if (av_strstart(keyval, "agroup:", &val)) { } else if (av_strstart(keyval, "agroup:", &val)) {
av_free(vs->agroup);
vs->agroup = av_strdup(val); vs->agroup = av_strdup(val);
if (!vs->agroup) if (!vs->agroup)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
continue; continue;
} else if (av_strstart(keyval, "ccgroup:", &val)) { } else if (av_strstart(keyval, "ccgroup:", &val)) {
av_free(vs->ccgroup);
vs->ccgroup = av_strdup(val); vs->ccgroup = av_strdup(val);
if (!vs->ccgroup) if (!vs->ccgroup)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -2048,14 +2052,17 @@ static int parse_cc_stream_mapstring(AVFormatContext *s)
ccstr = NULL; ccstr = NULL;
if (av_strstart(keyval, "ccgroup:", &val)) { if (av_strstart(keyval, "ccgroup:", &val)) {
av_free(ccs->ccgroup);
ccs->ccgroup = av_strdup(val); ccs->ccgroup = av_strdup(val);
if (!ccs->ccgroup) if (!ccs->ccgroup)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} else if (av_strstart(keyval, "instreamid:", &val)) { } else if (av_strstart(keyval, "instreamid:", &val)) {
av_free(ccs->instreamid);
ccs->instreamid = av_strdup(val); ccs->instreamid = av_strdup(val);
if (!ccs->instreamid) if (!ccs->instreamid)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} else if (av_strstart(keyval, "language:", &val)) { } else if (av_strstart(keyval, "language:", &val)) {
av_free(ccs->language);
ccs->language = av_strdup(val); ccs->language = av_strdup(val);
if (!ccs->language) if (!ccs->language)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);