summaryrefslogtreecommitdiff
path: root/libavutil/dict.c
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2014-07-29 21:23:57 +0200
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2014-08-16 14:47:06 +0200
commitbddc592001bd041511f4086a7d15611ec695e606 (patch)
tree9bddd82048ec3a665932d3ec02675ce599ca5f01 /libavutil/dict.c
parenta0941c8a2b3e55dc4482c874523afcb7ed6e93e6 (diff)
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>
Diffstat (limited to 'libavutil/dict.c')
-rw-r--r--libavutil/dict.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/libavutil/dict.c b/libavutil/dict.c
index 9fdc6d6273..c17ce7a3cb 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -91,7 +91,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
AVDictionaryEntry *tmp = av_realloc(m->elems,
(m->count + 1) * sizeof(*m->elems));
if (!tmp)
- return AVERROR(ENOMEM);
+ goto err_out;
m->elems = tmp;
}
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;
char *newval = av_mallocz(len);
if (!newval)
- return AVERROR(ENOMEM);
+ goto err_out;
av_strlcat(newval, oldval, len);
av_freep(&oldval);
av_strlcat(newval, value, len);
@@ -120,6 +120,13 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
}
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,