Index: libavformat/avio.c
===================================================================
--- libavformat/avio.c	(revision 22693)
+++ libavformat/avio.c	(working copy)
@@ -211,13 +211,13 @@
     int ret = 0;
     if (!h) return 0; /* can happen when url_open fails */
 
-    if (h->prot->url_close)
-        ret = h->prot->url_close(h);
+    ret = url_fdclose(h);
+
 #if CONFIG_NETWORK
-    ff_network_close();
+	ff_network_close();
 #endif
-    av_free(h);
-    return ret;
+
+	return ret;
 }
 
 int url_exist(const char *filename)
Index: libavformat/avio.h
===================================================================
--- libavformat/avio.h	(revision 22693)
+++ libavformat/avio.h	(working copy)
@@ -402,6 +402,8 @@
  */
 int url_fdopen(ByteIOContext **s, URLContext *h);
 
+int url_fdclose(ByteIOContext *s);
+
 /** @warning must be called before any I/O */
 int url_setbufsize(ByteIOContext *s, int buf_size);
 #if LIBAVFORMAT_VERSION_MAJOR < 53
Index: libavformat/aviobuf.c
===================================================================
--- libavformat/aviobuf.c	(revision 22693)
+++ libavformat/aviobuf.c	(working copy)
@@ -572,6 +572,18 @@
     return 0;
 }
 
+int url_fdclose(ByteIOContext *s)
+{
+    int ret = 0;
+    if (!h) return 0; /* can happen when url_open fails */
+
+    if (h->prot->url_close)
+        ret = h->prot->url_close(h);
+
+	av_free(h);
+    return ret;
+}
+
 int url_setbufsize(ByteIOContext *s, int buf_size)
 {
     uint8_t *buffer;
