diff mbox

[FFmpeg-devel,12/16] avformat/hlsenc: Unconditionally free some strings

Message ID 20191216000418.24707-13-andreas.rheinhardt@gmail.com
State Superseded
Headers show

Commit Message

Andreas Rheinhardt Dec. 16, 2019, 12:04 a.m. UTC
hls_init() would at first allocate the vtt_basename string, then
allocate the vtt_m3u8_name string followed by several operations that
may fail and then open the subtitles' output context. Yet upon freeing,
these strings were only freed when the subtitles' output context
existed, ensuring that they leak if something goes wrong between their
allocation and the opening of the subtitles' output context. So drop the
check for whether this output context exists.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/hlsenc.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Steven Liu Dec. 16, 2019, 3:08 a.m. UTC | #1
> 在 2019年12月16日,08:04,Andreas Rheinhardt <andreas.rheinhardt@gmail.com> 写道:
> 
> hls_init() would at first allocate the vtt_basename string, then
> allocate the vtt_m3u8_name string followed by several operations that
> may fail and then open the subtitles' output context. Yet upon freeing,
> these strings were only freed when the subtitles' output context
> existed, ensuring that they leak if something goes wrong between their
> allocation and the opening of the subtitles' output context. So drop the
> check for whether this output context exists.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> libavformat/hlsenc.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index d5682caaf7..d738b08a3f 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -2507,12 +2507,10 @@ static void hls_deinit(AVFormatContext *s)
>         av_freep(&vs->basename);
>         av_freep(&vs->base_output_dirname);
>         av_freep(&vs->fmp4_init_filename);
> -        if (vtt_oc) {
> -            av_freep(&vs->vtt_basename);
> -            av_freep(&vs->vtt_m3u8_name);
> -            avformat_free_context(vtt_oc);
> -        }
> +        av_freep(&vs->vtt_basename);
> +        av_freep(&vs->vtt_m3u8_name);
> 
> +        avformat_free_context(vtt_oc);
>         avformat_free_context(vs->avf);
> 
>         hls_free_segments(vs->segments);
> -- 
> 2.20.1
> 
> _______________________________________________
> 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”.

maybe this patch can merge into the [PATCH 08/16] avformat/hlsenc: Add deinit function

Thanks
Steven
diff mbox

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index d5682caaf7..d738b08a3f 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2507,12 +2507,10 @@  static void hls_deinit(AVFormatContext *s)
         av_freep(&vs->basename);
         av_freep(&vs->base_output_dirname);
         av_freep(&vs->fmp4_init_filename);
-        if (vtt_oc) {
-            av_freep(&vs->vtt_basename);
-            av_freep(&vs->vtt_m3u8_name);
-            avformat_free_context(vtt_oc);
-        }
+        av_freep(&vs->vtt_basename);
+        av_freep(&vs->vtt_m3u8_name);
 
+        avformat_free_context(vtt_oc);
         avformat_free_context(vs->avf);
 
         hls_free_segments(vs->segments);