Commit 1279221c authored by Luca Barbato's avatar Luca Barbato Committed by Vittorio Giovara

lavu: Check av_dict_set allocations

Bug-Id: CID 1257772
Signed-off-by: 's avatarVittorio Giovara <vittorio.giovara@gmail.com>
parent 6996fd20
...@@ -71,9 +71,12 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, ...@@ -71,9 +71,12 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
AVDictionary *m = *pm; AVDictionary *m = *pm;
AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags); AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
char *oldval = NULL; char *oldval = NULL;
int allocated = !!m;
if (!m) if (!m)
m = *pm = av_mallocz(sizeof(*m)); m = *pm = av_mallocz(sizeof(*m));
if (!m)
return AVERROR(ENOMEM);
if (tag) { if (tag) {
if (flags & AV_DICT_DONT_OVERWRITE) { if (flags & AV_DICT_DONT_OVERWRITE) {
...@@ -88,12 +91,14 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, ...@@ -88,12 +91,14 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
av_free(tag->key); av_free(tag->key);
*tag = m->elems[--m->count]; *tag = m->elems[--m->count];
} else { } else {
AVDictionaryEntry *tmp = av_realloc(m->elems, int ret = av_reallocp_array(&m->elems,
(m->count + 1) * sizeof(*m->elems)); m->count + 1, sizeof(*m->elems));
if (tmp) if (ret < 0) {
m->elems = tmp; if (allocated)
else av_freep(pm);
return AVERROR(ENOMEM);
return ret;
}
} }
if (value) { if (value) {
if (flags & AV_DICT_DONT_STRDUP_KEY) if (flags & AV_DICT_DONT_STRDUP_KEY)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment