[FFmpeg-devel] [PATCH] avformat/hlsenc: fix memleak

Aaron Levinson alevinsn at aracnet.com
Tue May 9 23:33:11 EEST 2017


On 5/8/2017 3:35 AM, Steven Liu wrote:
> fix memleak bug, when all the process is normal,
> just free old_filename
>
> Signed-off-by: Steven Liu <lq at chinaffmpeg.org>
> ---
>  libavformat/hlsenc.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 221089c..d62d5b8 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1559,6 +1559,8 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
>              av_free(old_filename);
>              return ret;
>          }
> +
> +        av_free(old_filename);

This looks fine, but, if possible, it would be preferable to free the 
memory earlier if it is no longer needed.  I didn't study the code 
sufficiently to determine this with certainty, but it is possible that 
old_filename is no longer needed after line 1551.  In that case, free it 
earlier and eliminate any subsequent calls to av_free(old_filename).

>      }
>
>      ret = ff_write_chained(oc, stream_index, pkt, s, 0);
>

Aaron Levinson


More information about the ffmpeg-devel mailing list