diff mbox

[FFmpeg-devel,1/2] fftools/ffmpeg: fix memory leak issue.

Message ID 1528897739-3704-1-git-send-email-mypopydev@gmail.com
State New
Headers show

Commit Message

Jun Zhao June 13, 2018, 1:48 p.m. UTC
need to call av_bprint_finalize to free the memory source to match
av_bprint_init.

Signed-off-by: Jun Zhao <mypopydev@gmail.com>
---
 fftools/ffmpeg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nicolas George June 14, 2018, 1:44 p.m. UTC | #1
Jun Zhao (2018-06-13):
> need to call av_bprint_finalize to free the memory source to match
> av_bprint_init.

As you may have seen, in this case too, the buffer is never allocated
dynamically.

The av_bprint_finalize() already present is thus useless (I think the
mistake is mine), but not harmful either.

Regards,
mypopy@gmail.com June 15, 2018, 12:06 a.m. UTC | #2
On Thu, Jun 14, 2018 at 9:44 PM Nicolas George <george@nsup.org> wrote:
>
> Jun Zhao (2018-06-13):
> > need to call av_bprint_finalize to free the memory source to match
> > av_bprint_init.
>
> As you may have seen, in this case too, the buffer is never allocated
> dynamically.
>
> The av_bprint_finalize() already present is thus useless (I think the
>  )mistake is mine), but not harmful either.
>
Yes, sometimes we didn't need to call av_bprint_finalize() because
bprint just uses a fixed buffer (1024 - size of  internal filed), but
as my opinion, is it needed to recommend the caller call
av_bprint_finalize() to prevent a potential memory leak if bprint
using dynamically buffer and in fixed buffer case, call
av_bprint_finalize() is not  harmful too?  Just a recommendation.
>
> --
>   Nicolas George
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
diff mbox

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d4ac690..cbe89a9 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1832,13 +1832,13 @@  static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
         avio_write(progress_avio, buf_script.str,
                    FFMIN(buf_script.len, buf_script.size - 1));
         avio_flush(progress_avio);
-        av_bprint_finalize(&buf_script, NULL);
         if (is_last_report) {
             if ((ret = avio_closep(&progress_avio)) < 0)
                 av_log(NULL, AV_LOG_ERROR,
                        "Error closing progress log, loss of information possible: %s\n", av_err2str(ret));
         }
     }
+    av_bprint_finalize(&buf_script, NULL);
 
     if (is_last_report)
         print_final_stats(total_size);