[FFmpeg-devel] [PATCH 1/5] lavu/dict: check for malloc failures

wm4 nfxjfg at googlemail.com
Fri Dec 12 18:15:39 CET 2014


---
I didn't actually test these fixes, because someone just passed me
a list of failures found with failmalloc, rather than providing
reproducible test cases.
---
 libavutil/dict.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavutil/dict.c b/libavutil/dict.c
index 2983ea5..a362de0 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -75,6 +75,8 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
 
     if (!m)
         m = *pm = av_mallocz(sizeof(*m));
+    if (!m)
+        goto err_out;
 
     if (tag) {
         if (flags & AV_DICT_DONT_OVERWRITE) {
@@ -100,6 +102,8 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
             m->elems[m->count].key = (char*)(intptr_t)key;
         else
             m->elems[m->count].key = av_strdup(key);
+        if (!m->elems[m->count].key)
+            goto err_out;
         if (flags & AV_DICT_DONT_STRDUP_VAL) {
             m->elems[m->count].value = (char*)(intptr_t)value;
         } else if (oldval && flags & AV_DICT_APPEND) {
@@ -123,7 +127,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
     return 0;
 
 err_out:
-    if (!m->count) {
+    if (m && !m->count) {
         av_free(m->elems);
         av_freep(pm);
     }
-- 
2.1.1



More information about the ffmpeg-devel mailing list