[FFmpeg-devel] [PATCH] lavc/utils: fix audio frame memleak in case of non refcounted frames.

Hendrik Leppkes h.leppkes at gmail.com
Wed Mar 20 11:25:16 CET 2013


On Tue, Mar 19, 2013 at 10:49 PM, Clément Bœsch <ubitux at gmail.com> wrote:
> This is a simple code duplication from what's in the decode video
> function. This change notably fixes leaks with the metadata filter
> tests.
> ---
>  libavcodec/utils.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index b245914..424ffab 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -2116,6 +2116,13 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
>
>          if (ret < 0 && frame->data[0])
>              av_frame_unref(frame);
> +
> +        if (*got_frame_ptr) {
> +            if (!avctx->refcounted_frames) {
> +                avci->to_free = *frame;
> +                avci->to_free.extended_data = avci->to_free.data;
> +            }
> +        }
>      }
>
>      /* many decoders assign whole AVFrames, thus overwriting extended_data;
> --
> 1.8.2
>

This piece of code is already in that function, line 2066.
I was a bit confused, because i only converted my video to refcounted
frames, and would've noticed such a bad leak.

The problem appears to be that the metadata is only added into the
frame after the frame is assigned to avci->to_free in the existing
block, and thus leaks.
Maybe add_metadata_from_side_data should be moved into the block thats
only run on successfull decoding, ie. a few lines above it - before
the code that sets avci->to_free

- Hendrik


More information about the ffmpeg-devel mailing list