diff mbox

[FFmpeg-devel] avformat/hlsenc: Fix memleak when using single_file

Message ID 20190911123636.59733-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 1a066d87e3ea2fb8139af9181b3abf0f0a16a208
Headers show

Commit Message

Andreas Rheinhardt Sept. 11, 2019, 12:36 p.m. UTC
This commit fixes a memleak in the hls muxer when one uses a single file
as output. It has been forgotten to free the temporary buffers used to write
the packets so that the size of the leaks basically amounts to the size
of the output file. This commit adds the necessary free.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
I used av_freep instead of av_free (as happens in other places) in order
not to leave an inconsistent state behind. There is actually no reason
to keep the pointer to the temporary buffer; an automatic variable would
be enough.
Furthermore, if flush_dynbuf fails at opening a new dynamic buffer, the
temporary buffer needs to be freed nevertheless. Yet this isn't done for
the other two calls to flush_dynbuf.

 libavformat/hlsenc.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Liu Steven Sept. 12, 2019, 1:38 a.m. UTC | #1
> 在 2019年9月11日,下午8:36,Andreas Rheinhardt <andreas.rheinhardt@gmail.com> 写道:
> 
> This commit fixes a memleak in the hls muxer when one uses a single file
> as output. It has been forgotten to free the temporary buffers used to write
> the packets so that the size of the leaks basically amounts to the size
> of the output file. This commit adds the necessary free.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> I used av_freep instead of av_free (as happens in other places) in order
> not to leave an inconsistent state behind. There is actually no reason
> to keep the pointer to the temporary buffer; an automatic variable would
> be enough.
> Furthermore, if flush_dynbuf fails at opening a new dynamic buffer, the
> temporary buffer needs to be freed nevertheless. Yet this isn't done for
> the other two calls to flush_dynbuf.
> 
> libavformat/hlsenc.c | 1 +
> 1 file changed, 1 insertion(+)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index f881bb9d60..a6a3947ac7 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -2365,6 +2365,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
> 
>         if (hls->flags & HLS_SINGLE_FILE) {
>             ret = flush_dynbuf(vs, &range_length);
> +            av_freep(&vs->temp_buffer);
>             if (ret < 0) {
>                 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".


LGTM

Thanks
Steven
diff mbox

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f881bb9d60..a6a3947ac7 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2365,6 +2365,7 @@  static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
 
         if (hls->flags & HLS_SINGLE_FILE) {
             ret = flush_dynbuf(vs, &range_length);
+            av_freep(&vs->temp_buffer);
             if (ret < 0) {
                 return ret;
             }