diff --git a/doc/APIchanges b/doc/APIchanges
index 57ef04f422655673daf0626cfb86e49f6b830b3a..c6242eef1cd7992eee7840ecaf4af80d886742b8 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,10 @@ libavutil:     2013-12-xx
 
 API changes, most recent first:
 
+2014-04-xx - xxxxxxx - lavc 55.52.0 - avcodec.h
+  Add avcodec_free_context(). From now on it should be used for freeing
+  AVCodecContext.
+
 2014-05-xx - xxxxxxx - lavf 55.17.0 - avformat.h
   Add AVMFT_FLAG_BITEXACT flag. Muxers now use it instead of checking
   CODEC_FLAG_BITEXACT on the first stream.
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index c76ee04cf5835b9172539e8d5727941a0202d31d..56407108501e447c26298c66212a59a0cb200454 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3146,9 +3146,8 @@ void avcodec_register(AVCodec *codec);
 void avcodec_register_all(void);
 
 /**
- * Allocate an AVCodecContext and set its fields to default values.  The
- * resulting struct can be deallocated by calling avcodec_close() on it followed
- * by av_free().
+ * Allocate an AVCodecContext and set its fields to default values. The
+ * resulting struct should be freed with avcodec_free_context().
  *
  * @param codec if non-NULL, allocate private data and initialize defaults
  *              for the given codec. It is illegal to then call avcodec_open2()
@@ -3162,6 +3161,12 @@ void avcodec_register_all(void);
  */
 AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);
 
+/**
+ * Free the codec context and everything associated with it and write NULL to
+ * the provided pointer.
+ */
+void avcodec_free_context(AVCodecContext **avctx);
+
 /**
  * Set the fields of the given AVCodecContext to default values corresponding
  * to the given codec (defaults may be codec-dependent).
diff --git a/libavcodec/options.c b/libavcodec/options.c
index 85c1bec9bedf9ad6219cdd7571c3c7aca32543f4..e3ded738bb64e378c26e96f94174e1351b7f2475 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;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 22343d53966772aea3bb9c378bddd28dd7a7d2be..d42e963d40e800dd92a2b97b721175771afd3fe4 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 55
-#define LIBAVCODEC_VERSION_MINOR 51
+#define LIBAVCODEC_VERSION_MINOR 52
 #define LIBAVCODEC_VERSION_MICRO  0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \