[FFmpeg-cvslog] libavutil/opt: fix memory leak after av_dict_parse_string fail

Jun Zhao git at videolan.org
Sat Jan 4 03:07:19 EET 2020


ffmpeg | branch: master | Jun Zhao <barryjzhao at tencent.com> | Wed Jan  1 12:35:31 2020 +0800| [3c8da7b9826d03e370cab550a403ed0e14da24ef] | committer: Jun Zhao

libavutil/opt: fix memory leak after av_dict_parse_string fail

In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Jun Zhao <barryjzhao at tencent.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3c8da7b9826d03e370cab550a403ed0e14da24ef
---

 libavutil/opt.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 60161d4a80..a482febf5f 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -452,8 +452,10 @@ static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_
 
     if (val) {
         int ret = av_dict_parse_string(&options, val, "=", ":", 0);
-        if (ret < 0)
+        if (ret < 0) {
+            av_dict_free(&options);
             return ret;
+        }
     }
 
     av_dict_free((AVDictionary **)dst);
@@ -2006,8 +2008,10 @@ int av_opt_is_set_to_default(void *obj, const AVOption *o)
         AVDictionaryEntry *en1 = NULL;
         AVDictionaryEntry *en2 = NULL;
         ret = av_dict_parse_string(&dict1, o->default_val.str, "=", ":", 0);
-        if (ret < 0)
+        if (ret < 0) {
+            av_dict_free(&dict1);
             return ret;
+        }
         do {
             en1 = av_dict_get(dict1, "", en1, AV_DICT_IGNORE_SUFFIX);
             en2 = av_dict_get(dict2, "", en2, AV_DICT_IGNORE_SUFFIX);



More information about the ffmpeg-cvslog mailing list