diff mbox

[FFmpeg-devel] avcodec/mpegvideo_enc: fix memory leak

Message ID 20160925134306.1690-1-timo@rothenpieler.org
State Accepted
Commit 99b823f0a1be42abc0f3a6a0da946c4464db5fb6
Headers show

Commit Message

Timo Rothenpieler Sept. 25, 2016, 1:43 p.m. UTC
When the input frames contain side data, it will accumulate endlessly in
the coded frame, as av_frame_copy_props will append any new side data.
---
 libavcodec/mpegvideo_enc.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Carl Eugen Hoyos Sept. 25, 2016, 1:44 p.m. UTC | #1
2016-09-25 15:43 GMT+02:00 Timo Rothenpieler <timo@rothenpieler.org>:
> When the input frames contain side data, it will accumulate endlessly in
> the coded frame, as av_frame_copy_props will append any new side data.

But there is no leak, no?
Is this related to ticket #5799?

Carl Eugen
Timo Rothenpieler Sept. 25, 2016, 1:47 p.m. UTC | #2
On 9/25/2016 3:44 PM, Carl Eugen Hoyos wrote:
> 2016-09-25 15:43 GMT+02:00 Timo Rothenpieler <timo@rothenpieler.org>:
>> When the input frames contain side data, it will accumulate endlessly in
>> the coded frame, as av_frame_copy_props will append any new side data.
> 
> But there is no leak, no?
> Is this related to ticket #5799?

This fixes that ticket for me, yes.
And without this, ffmpeg keeps using more and more memory.
So while the memory is eventually freed when the encoding is done, it
still seems like a leak to me.
Carl Eugen Hoyos Sept. 25, 2016, 1:55 p.m. UTC | #3
2016-09-25 15:47 GMT+02:00 Timo Rothenpieler <timo@rothenpieler.org>:
> On 9/25/2016 3:44 PM, Carl Eugen Hoyos wrote:
>> 2016-09-25 15:43 GMT+02:00 Timo Rothenpieler <timo@rothenpieler.org>:
>>> When the input frames contain side data, it will accumulate
>>> endlessly in the coded frame, as av_frame_copy_props will
>>> append any new side data.
>>
>> But there is no leak, no?
>> Is this related to ticket #5799?
>
> This fixes that ticket for me, yes.

Please mention this in the commit message.

> And without this, ffmpeg keeps using more and more memory.
> So while the memory is eventually freed when the encoding is done

I believe this defines it as not being a leak.

Thank you for fixing this, Carl Eugen
Timo Rothenpieler Sept. 25, 2016, 1:59 p.m. UTC | #4
On 9/25/2016 3:55 PM, Carl Eugen Hoyos wrote:
> 2016-09-25 15:47 GMT+02:00 Timo Rothenpieler <timo@rothenpieler.org>:
>> On 9/25/2016 3:44 PM, Carl Eugen Hoyos wrote:
>>> 2016-09-25 15:43 GMT+02:00 Timo Rothenpieler <timo@rothenpieler.org>:
>>>> When the input frames contain side data, it will accumulate
>>>> endlessly in the coded frame, as av_frame_copy_props will
>>>> append any new side data.
>>>
>>> But there is no leak, no?
>>> Is this related to ticket #5799?
>>
>> This fixes that ticket for me, yes.
> 
> Please mention this in the commit message.
> 

Added locally.

>> And without this, ffmpeg keeps using more and more memory.
>> So while the memory is eventually freed when the encoding is done
> 
> I believe this defines it as not being a leak.

What else would it be? I think speaking of a leak here is still valid.

> Thank you for fixing this, Carl Eugen
Nicolas George Sept. 25, 2016, 2 p.m. UTC | #5
Le quartidi 4 vendémiaire, an CCXXV, Carl Eugen Hoyos a écrit :
> > And without this, ffmpeg keeps using more and more memory.
> > So while the memory is eventually freed when the encoding is done
> I believe this defines it as not being a leak.

I believe you are wrong. It is not the same kind of leaks than usual, and
not the kind of leak that valgrind can detect, but any repeated allocations
that are not freed in a timely fashion when they are not needed anymore
constitute a leak.

Regards,
Carl Eugen Hoyos Sept. 25, 2016, 2:01 p.m. UTC | #6
2016-09-25 15:59 GMT+02:00 Timo Rothenpieler <timo@rothenpieler.org>:

>>> And without this, ffmpeg keeps using more and more memory.
>>> So while the memory is eventually freed when the encoding is done
>>
>> I believe this defines it as not being a leak.
>
> What else would it be?

(Massive) memory consumption.

Carl Eugen
Carl Eugen Hoyos Sept. 25, 2016, 2:02 p.m. UTC | #7
2016-09-25 16:00 GMT+02:00 Nicolas George <george@nsup.org>:
> Le quartidi 4 vendémiaire, an CCXXV, Carl Eugen Hoyos a écrit :
>> > And without this, ffmpeg keeps using more and more memory.
>> > So while the memory is eventually freed when the encoding is done
>> I believe this defines it as not being a leak.
>
> I believe you are wrong. It is not the same kind of leaks than usual, and
> not the kind of leak that valgrind can detect, but any repeated allocations
> that are not freed in a timely fashion when they are not needed anymore
> constitute a leak.

Fine with me.
(I am just surprised that other developers have often used
another definition on our various bug trackers that makes
much more sense to me.)

Carl Eugen
Nicolas George Sept. 25, 2016, 2:05 p.m. UTC | #8
Le quartidi 4 vendémiaire, an CCXXV, Carl Eugen Hoyos a écrit :
> (Massive) memory consumption.

That would be if the consumption was necessary.

Regards,
Timo Rothenpieler Sept. 26, 2016, 8:18 a.m. UTC | #9
> When the input frames contain side data, it will accumulate endlessly in
> the coded frame, as av_frame_copy_props will append any new side data.
> ---
>  libavcodec/mpegvideo_enc.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
> index 87d7954..5cd654f 100644
> --- a/libavcodec/mpegvideo_enc.c
> +++ b/libavcodec/mpegvideo_enc.c
> @@ -1735,6 +1735,7 @@ static void frame_end(MpegEncContext *s)
>  
>  #if FF_API_CODED_FRAME
>  FF_DISABLE_DEPRECATION_WARNINGS
> +    av_frame_unref(s->avctx->coded_frame);
>      av_frame_copy_props(s->avctx->coded_frame, s->current_picture.f);
>  FF_ENABLE_DEPRECATION_WARNINGS
>  #endif
> 

Will push later today, unless someone has a better idea how to address
this issue.
Maybe some way to not use av_frame_copy_props in the first place?
Timo Rothenpieler Sept. 26, 2016, 4:46 p.m. UTC | #10
> Will push later today, unless someone has a better idea how to address
> this issue.
> Maybe some way to not use av_frame_copy_props in the first place?

applied
diff mbox

Patch

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 87d7954..5cd654f 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1735,6 +1735,7 @@  static void frame_end(MpegEncContext *s)
 
 #if FF_API_CODED_FRAME
 FF_DISABLE_DEPRECATION_WARNINGS
+    av_frame_unref(s->avctx->coded_frame);
     av_frame_copy_props(s->avctx->coded_frame, s->current_picture.f);
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif