[FFmpeg-devel,v2,1/2] avformat/hlsenc: free the original malloc pointer to avoid error when system function used in the following patch

Submitted by lance.lmwang@gmail.com on Oct. 9, 2019, 9:10 a.m.

Details

Message ID 20191009091055.32508-1-lance.lmwang@gmail.com
State New
Headers show

Commit Message

lance.lmwang@gmail.com Oct. 9, 2019, 9:10 a.m.
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
git format the patch on master, the v1 depend on other patch and can't git am
directly.

 libavformat/hlsenc.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index cd43201..3cdc468 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -487,8 +487,11 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
     int ret = 0, path_size, sub_path_size;
     int segment_cnt = 0;
     char *dirname = NULL, *sub_path;
+    char *dirname_r = NULL;
+    char *r_dirname = NULL;
     char *path = NULL;
     char *vtt_dirname = NULL;
+    char *vtt_dirname_r = NULL;
     AVDictionary *options = NULL;
     AVIOContext *out = NULL;
     const char *proto = NULL;
@@ -517,7 +520,7 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
     }
 
     if (segment && !hls->use_localtime_mkdir) {
-        char *dirname_r = hls->segment_filename ? av_strdup(hls->segment_filename): av_strdup(vs->avf->url);
+        dirname_r = hls->segment_filename ? av_strdup(hls->segment_filename): av_strdup(vs->avf->url);
         dirname = (char*)av_dirname(dirname_r);
     }
 
@@ -537,7 +540,6 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
             }
         }
 
-        av_freep(&dirname);
         dirname = r_dirname;
     }
 
@@ -573,7 +575,7 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
         }
 
         if ((segment->sub_filename[0] != '\0')) {
-            char *vtt_dirname_r = av_strdup(vs->vtt_avf->url);
+            vtt_dirname_r = av_strdup(vs->vtt_avf->url);
             vtt_dirname = (char*)av_dirname(vtt_dirname_r);
             sub_path_size = strlen(segment->sub_filename) + 1 + strlen(vtt_dirname);
             sub_path = av_malloc(sub_path_size);
@@ -608,8 +610,9 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
 
 fail:
     av_freep(&path);
-    av_freep(&dirname);
-    av_freep(&vtt_dirname);
+    av_freep(&dirname_r);
+    av_freep(&r_dirname);
+    av_freep(&vtt_dirname_r);
 
     return ret;
 }