[FFmpeg-devel,v1,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, 8:28 a.m.

Details

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

Commit Message

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

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavformat/hlsenc.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Steven Liu Oct. 9, 2019, 8:52 a.m.
> 在 2019年10月9日,16:28,lance.lmwang@gmail.com 写道:
> 
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
> libavformat/hlsenc.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index b9f5b69fcf..5d8c4a3a8f 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -493,8 +493,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;
maybe dirname_r and r_dirname should make ?
>     char *path = NULL;
>     char *vtt_dirname = NULL;
> +    char *vtt_dirname_r = NULL;
>     AVDictionary *options = NULL;
>     AVIOContext *out = NULL;
>     const char *proto = NULL;
> @@ -523,7 +526,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);
>     }
> 
> @@ -543,7 +546,6 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
>             }
>         }
> 
> -        av_freep(&dirname);
remove this line will memleak, because the replace_int_data_in_filename and replace_str_data_in_filename will get new memory to r_dirname.

>         dirname = r_dirname;
>     }
> 
> @@ -578,7 +580,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) + 1;
>             sub_path = av_malloc(sub_path_size);
> @@ -612,8 +614,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;
> }
> -- 
> 2.21.0
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

Thanks
Steven

Patch hide | download patch | download mbox

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index b9f5b69fcf..5d8c4a3a8f 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -493,8 +493,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;
@@ -523,7 +526,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);
     }
 
@@ -543,7 +546,6 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
             }
         }
 
-        av_freep(&dirname);
         dirname = r_dirname;
     }
 
@@ -578,7 +580,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) + 1;
             sub_path = av_malloc(sub_path_size);
@@ -612,8 +614,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;
 }