[FFmpeg-devel] [PATCH v0 02/14] avcodec: move AVCodecInternal allocation to avcodec_alloc_context3

Anton Khirnov anton at khirnov.net
Fri Mar 24 15:20:29 EET 2023


Quoting James Almer (2023-03-24 14:02:40)
> On 3/24/2023 9:07 AM, Andreas Rheinhardt wrote:
> >> @@ -174,6 +190,8 @@ void avcodec_free_context(AVCodecContext **pavctx)
> >>   
> >>       avcodec_close(avctx);
> >>   
> >> +    av_freep(&avctx->internal);
> > Moving this to avcodec_free_context() creates a leak when using
> > avcodec_close()+av_free(). This can be fixed by allocating the
> > AVCodecContext and the AVCodecInternal jointly.
> 
> Can't we just declare that doing av_free() on a AVCodecContext is not a 
> valid API usage? Every other struct with an specific free function is 
> very clear about it being the only way to free them.

Sadly I expect many callers still do this, even though
avcodec_free_context() has existed since 2014. The proper solution is to
deprecated avcodec_close(), but that needs a new parser API.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list