summaryrefslogtreecommitdiff
path: root/libavcodec/options.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2014-04-05 08:36:00 +0200
committerAnton Khirnov <anton@khirnov.net>2014-05-18 10:17:41 +0200
commitfd056029f45a9f6d213d9fce8165632042511d4f (patch)
treea8d099315752e011355e129cda5a77e50e5444d2 /libavcodec/options.c
parente1b66778b6ee82a192b5895e23c4e135f7269326 (diff)
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.
Diffstat (limited to 'libavcodec/options.c')
-rw-r--r--libavcodec/options.c15
1 files changed, 15 insertions, 0 deletions
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;