dict.c: empty dictionaries should be a NULL pointer.

Ensure this is even the case if they are empty because
we failed adding the first entry.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
This commit is contained in:
Reimar Döffinger 2014-07-29 21:23:57 +02:00
parent a0941c8a2b
commit bddc592001
1 changed files with 9 additions and 2 deletions

View File

@ -91,7 +91,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
AVDictionaryEntry *tmp = av_realloc(m->elems, AVDictionaryEntry *tmp = av_realloc(m->elems,
(m->count + 1) * sizeof(*m->elems)); (m->count + 1) * sizeof(*m->elems));
if (!tmp) if (!tmp)
return AVERROR(ENOMEM); goto err_out;
m->elems = tmp; m->elems = tmp;
} }
if (value) { if (value) {
@ -105,7 +105,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
int len = strlen(oldval) + strlen(value) + 1; int len = strlen(oldval) + strlen(value) + 1;
char *newval = av_mallocz(len); char *newval = av_mallocz(len);
if (!newval) if (!newval)
return AVERROR(ENOMEM); goto err_out;
av_strlcat(newval, oldval, len); av_strlcat(newval, oldval, len);
av_freep(&oldval); av_freep(&oldval);
av_strlcat(newval, value, len); av_strlcat(newval, value, len);
@ -120,6 +120,13 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
} }
return 0; return 0;
err_out:
if (!m->count) {
av_free(m->elems);
av_freep(pm);
}
return AVERROR(ENOMEM);
} }
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value,