From fd056029f45a9f6d213d9fce8165632042511d4f Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 5 Apr 2014 08:36:00 +0200 Subject: lavc: add avcodec_free_context(). Right now, the caller has to manually manage some allocated AVCodecContext fields, like extradata or subtitle_header. This is fragile and prone to leaks, especially if we want to add more such fields in the future. The only reason for this behaviour is so that the AVStream codec context can be reused for decoding. Such reuse is discouraged anyway, so this commit is the first step to deprecating it. --- libavcodec/options.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libavcodec/options.c') diff --git a/libavcodec/options.c b/libavcodec/options.c index 85c1bec9be..e3ded738bb 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -135,6 +135,21 @@ AVCodecContext *avcodec_alloc_context3(const AVCodec *codec) return avctx; } +void avcodec_free_context(AVCodecContext **pavctx) +{ + AVCodecContext *avctx = *pavctx; + + if (!avctx) + return; + + avcodec_close(avctx); + + av_freep(&avctx->extradata); + av_freep(&avctx->subtitle_header); + + av_freep(pavctx); +} + int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) { const AVCodec *orig_codec = dest->codec; -- cgit v1.2.3