diff -Naur master-20130903.orig/libavformat/utils.c master-20130903/libavformat/utils.c
--- master-20130903.orig/libavformat/utils.c	2013-09-03 13:33:49.000000000 -0500
+++ master-20130903/libavformat/utils.c	2013-09-03 14:26:42.000000000 -0500
@@ -3201,9 +3201,10 @@
     av_dict_free(&st->metadata);
     av_freep(&st->probe_data.buf);
     av_freep(&st->index_entries);
-    av_freep(&st->codec->extradata);
-    av_freep(&st->codec->subtitle_header);
-    av_freep(&st->codec);
+    if (st->codec) {
+        avcodec_close(st->codec);
+        av_freep(&st->codec);
+    }
     av_freep(&st->priv_data);
     if (st->info)
         av_freep(&st->info->duration_error);
