[FFmpeg-cvslog] avio: add a destructor for AVIOContext

Anton Khirnov git at videolan.org
Thu Sep 28 02:56:33 EEST 2017


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Fri Jan 13 11:53:51 2017 +0100| [99684f3ae752fc8bfb44a2dd1482f8d7a3d8536d] | committer: Anton Khirnov

avio: add a destructor for AVIOContext

Before this commit, AVIOContext is to be freed with a plain av_free(),
which prevents us from adding any deeper structure to it.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=99684f3ae752fc8bfb44a2dd1482f8d7a3d8536d
---

 doc/APIchanges        |  3 +++
 libavformat/avio.h    |  8 ++++++++
 libavformat/aviobuf.c | 17 ++++++++++++++---
 libavformat/version.h |  4 ++--
 4 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index c161618d92..8c7d279fec 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2016-xx-xx - xxxxxxx - lavf 57.11.0 - avio.h
+  Add avio_context_free(). From now on it must be used for freeing AVIOContext.
+
 2017-02-01 - xxxxxxx - lavc - avcodec.h
   Deprecate AVCodecContext.refcounted_frames. This was useful for deprecated
   API only (avcodec_decode_video2/avcodec_decode_audio4). The new decode APIs
diff --git a/libavformat/avio.h b/libavformat/avio.h
index 7bf7985c5e..e65135ed99 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -219,6 +219,14 @@ AVIOContext *avio_alloc_context(
                   int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
                   int64_t (*seek)(void *opaque, int64_t offset, int whence));
 
+/**
+ * Free the supplied IO context and everything associated with it.
+ *
+ * @param s Double pointer to the IO context. This function will write NULL
+ * into s.
+ */
+void avio_context_free(AVIOContext **s);
+
 void avio_w8(AVIOContext *s, int b);
 void avio_write(AVIOContext *s, const unsigned char *buf, int size);
 void avio_wl64(AVIOContext *s, uint64_t val);
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 6d83a9661b..31476d3f6d 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -165,6 +165,11 @@ AVIOContext *avio_alloc_context(
     return s;
 }
 
+void avio_context_free(AVIOContext **ps)
+{
+    av_freep(ps);
+}
+
 static void flush_buffer(AVIOContext *s)
 {
     if (s->buf_ptr > s->buffer) {
@@ -1007,7 +1012,9 @@ int avio_close(AVIOContext *s)
     av_freep(&internal->protocols);
     av_freep(&s->opaque);
     av_freep(&s->buffer);
-    av_free(s);
+
+    avio_context_free(&s);
+
     return ffurl_close(h);
 }
 
@@ -1186,7 +1193,9 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
     *pbuffer = d->buffer;
     size = d->size;
     av_free(d);
-    av_free(s);
+
+    avio_context_free(&s);
+
     return size - padding;
 }
 
@@ -1229,6 +1238,8 @@ int ffio_close_null_buf(AVIOContext *s)
 
     size = d->size;
     av_free(d);
-    av_free(s);
+
+    avio_context_free(&s);
+
     return size;
 }
diff --git a/libavformat/version.h b/libavformat/version.h
index 65d5754630..92f3407909 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,8 +30,8 @@
 #include "libavutil/version.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 57
-#define LIBAVFORMAT_VERSION_MINOR 10
-#define LIBAVFORMAT_VERSION_MICRO  3
+#define LIBAVFORMAT_VERSION_MINOR 11
+#define LIBAVFORMAT_VERSION_MICRO  0
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list