summaryrefslogtreecommitdiff
path: root/libavutil/dict.c
diff options
context:
space:
mode:
authorLuca Barbato <lu_zero@gentoo.org>2014-12-16 14:21:20 +0100
committerVittorio Giovara <vittorio.giovara@gmail.com>2015-01-29 14:59:57 +0000
commit1279221cc4d63bc4449df86ae7a98e633f8be425 (patch)
treecfee728cadfb2a953ccb97a4899ca1083307c604 /libavutil/dict.c
parent6996fd204a7f28b46a8c3c97bcf223998218c743 (diff)
lavu: Check av_dict_set allocations
Bug-Id: CID 1257772 Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Diffstat (limited to 'libavutil/dict.c')
-rw-r--r--libavutil/dict.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/libavutil/dict.c b/libavutil/dict.c
index e4ea7769e0..7f4832092a 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -71,9 +71,12 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
AVDictionary *m = *pm;
AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
char *oldval = NULL;
+ int allocated = !!m;
if (!m)
m = *pm = av_mallocz(sizeof(*m));
+ if (!m)
+ return AVERROR(ENOMEM);
if (tag) {
if (flags & AV_DICT_DONT_OVERWRITE) {
@@ -88,12 +91,14 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
av_free(tag->key);
*tag = m->elems[--m->count];
} else {
- AVDictionaryEntry *tmp = av_realloc(m->elems,
- (m->count + 1) * sizeof(*m->elems));
- if (tmp)
- m->elems = tmp;
- else
- return AVERROR(ENOMEM);
+ int ret = av_reallocp_array(&m->elems,
+ m->count + 1, sizeof(*m->elems));
+ if (ret < 0) {
+ if (allocated)
+ av_freep(pm);
+
+ return ret;
+ }
}
if (value) {
if (flags & AV_DICT_DONT_STRDUP_KEY)