[FFmpeg-devel] [PATCH V1 10/12] lavf/hlsenc: fix memory leak after av_dict_parse_string fail

Jun Zhao mypopydev at gmail.com
Wed Jan 1 07:20:38 EET 2020


From: Jun Zhao <barryjzhao at 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 at tencent.com>
---
 libavformat/hlsenc.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 6551e1c..df19545 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -856,6 +856,7 @@ static int hls_mux_init(AVFormatContext *s, VariantStream *vs)
     if (hls->format_options_str) {
         ret = av_dict_parse_string(&hls->format_options, hls->format_options_str, "=", ":", 0);
         if (ret < 0) {
+            av_dict_free(&hls->format_options);
             av_log(s, AV_LOG_ERROR, "Could not parse format options list '%s'\n",
                    hls->format_options_str);
             return ret;
@@ -2781,6 +2782,7 @@ static int hls_init(AVFormatContext *s)
         if (hls->format_options_str) {
             ret = av_dict_parse_string(&hls->format_options, hls->format_options_str, "=", ":", 0);
             if (ret < 0) {
+                av_dict_free(&hls->format_options);
                 av_log(s, AV_LOG_ERROR, "Could not parse format options list '%s'\n", hls->format_options_str);
                 goto fail;
             }
-- 
1.7.1



More information about the ffmpeg-devel mailing list