diff mbox

[FFmpeg-devel] avformat/hlsenc: fix memleak

Message ID 20170508103535.23667-1-lq@chinaffmpeg.org
State New
Headers show

Commit Message

Steven Liu May 8, 2017, 10:35 a.m. UTC
fix memleak bug, when all the process is normal,
just free old_filename

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavformat/hlsenc.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Comments

Aaron Levinson May 9, 2017, 8:33 p.m. UTC | #1
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@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
diff mbox

Patch

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);
     }
 
     ret = ff_write_chained(oc, stream_index, pkt, s, 0);