diff mbox series

[FFmpeg-devel,V2,4/5] libavutil/opt: fix memory leak after av_dict_parse_string fail

Message ID 1577966105-4642-4-git-send-email-mypopydev@gmail.com
State New
Headers show
Series [FFmpeg-devel,V2,1/5] lavc/bsf: fix memory leak after av_dict_parse_string fail
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Jun Zhao Jan. 2, 2020, 11:55 a.m. UTC
From: Jun Zhao <barryjzhao@tencent.com>

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.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
---
 libavutil/opt.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer Jan. 2, 2020, 11:21 p.m. UTC | #1
On Thu, Jan 02, 2020 at 07:55:04PM +0800, Jun Zhao wrote:
> From: Jun Zhao <barryjzhao@tencent.com>
> 
> 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.
> 
> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> ---
>  libavutil/opt.c |    8 ++++++--
>  1 files changed, 6 insertions(+), 2 deletions(-)

LGTM

thx

[...]
diff mbox series

Patch

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 60161d4..a482feb 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);