[FFmpeg-devel] [PATCH] lavformat/utils: Fix a memleak that st->codec->hw_frames_ctx

Chao Liu chaox.a.liu at gmail.com
Mon Jan 23 03:40:05 EET 2017


On Sun, Jan 22, 2017 at 9:03 PM, Mark Thompson <sw at jkqxz.net> wrote:

> On 20/01/17 02:06, Huang, Zhengxu wrote:
> > From 9ceb2ac6a89246f2e686eb3ad3448fbaff5328f7 Mon Sep 17 00:00:00 2001
> > From: Zhengxu <zhengxu.maxwell at gmail.com>
> > Date: Fri, 13 Jan 2017 10:33:05 +0800
> > Subject: [PATCH] lavformat/utils: Fix a memleak that
> st->codec->hw_frames_ctx
> >  is not released.
> >
> > Signed-off-by: ChaoX A Liu <chaox.a.liu at gmail.com>
> > Signed-off-by: Huang, Zhengxu <zhengxu.maxwell at gmail.com>
> > Signed-off-by: Andrew, Zhang <huazh407 at gmail.com>
> > ---
> >  libavformat/utils.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/libavformat/utils.c b/libavformat/utils.c
> > index d5dfca7..cadec15 100644
> > --- a/libavformat/utils.c
> > +++ b/libavformat/utils.c
> > @@ -4127,6 +4127,7 @@ static void free_stream(AVStream **pst)
> >  FF_DISABLE_DEPRECATION_WARNINGS
> >      av_freep(&st->codec->extradata);
> >      av_freep(&st->codec->subtitle_header);
> > +    av_buffer_unref(&st->codec->hw_frames_ctx);
> >      av_freep(&st->codec);
> >  FF_ENABLE_DEPRECATION_WARNINGS
> >  #endif
> > --
> > 1.8.3.1
> >
>
> As stated elsewhere, this should never happen in a sane program
> (AVStream.codec was deprecated before AVCodecContext.hw_frames_ctx was
> introduced), but I admit that ffmpeg.c cannot be said to be a sane program.
>
> I think the patch is probably ok, but it is very difficult to tell.  Why
> doesn't the code here already call avcodec_free_context() here to free
> st->codec properly, including unreffing hw_frames_ctx?  I imagine there is
> some crazy reason for this (some fields have been copied somewhere else,
> maybe?), and without knowing that I don't think this patch should be
> applied.
>
> So, I mostly agree with Hendrik that it is probably better to fix ffmpeg.c
> to not cause the problem in the first place rather than changing this
> deprecated code in lavf.
>
> Thanks,
>
> - Mark


OK. Let's end this topic till we find out a graceful way to fix it.

Thanks for all your patient explaining.

Regards,
Chao


More information about the ffmpeg-devel mailing list