[FFmpeg-devel,3/5] avformat/hlsenc: fix memleak problem about fmp4_init_filename

Submitted by Steven Liu on March 12, 2018, 6:34 a.m.

Details

Message ID 20180312063459.14030-1-lq@chinaffmpeg.org
State Accepted
Commit c6086692645951264a4f98a3568f80b7c827a129
Headers show

Commit Message

Steven Liu March 12, 2018, 6:34 a.m.
move fmp4_init_filename init in if else for first fmp4_init_filename set
value operation.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavformat/hlsenc.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 7ca4099e7e..ad9f4d3394 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2574,6 +2574,13 @@  static int hls_init(AVFormatContext *s)
         if (hls->segment_type == SEGMENT_TYPE_FMP4) {
             if (hls->nb_varstreams > 1)
                 fmp4_init_filename_len += strlen(POSTFIX_PATTERN);
+            if (hls->flags & HLS_SINGLE_FILE) {
+                vs->fmp4_init_filename  = av_strdup(vs->basename);
+                if (!vs->fmp4_init_filename) {
+                    ret = AVERROR(ENOMEM);
+                    goto fail;
+                }
+            } else {
             vs->fmp4_init_filename = av_malloc(fmp4_init_filename_len);
             if (!vs->fmp4_init_filename ) {
                 ret = AVERROR(ENOMEM);
@@ -2607,6 +2614,7 @@  static int hls_init(AVFormatContext *s)
                 av_strlcpy(vs->base_output_dirname, vs->fmp4_init_filename,
                            fmp4_init_filename_len);
             }
+            }
         }
 
         if (!hls->use_localtime) {
@@ -2661,13 +2669,6 @@  static int hls_init(AVFormatContext *s)
             }
         }
 
-        if ((hls->flags & HLS_SINGLE_FILE) && (hls->segment_type == SEGMENT_TYPE_FMP4)) {
-            vs->fmp4_init_filename  = av_strdup(vs->basename);
-            if (!vs->fmp4_init_filename) {
-                ret = AVERROR(ENOMEM);
-                goto fail;
-            }
-        }
         if ((ret = hls_mux_init(s, vs)) < 0)
             goto fail;