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

Anton Khirnov git at videolan.org
Fri Sep 1 07:52:38 EEST 2017


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sun Aug 27 13:26:58 2017 -0300| [b12e4d3bb8df994f042ff1216fb8de2b967aab9e] | committer: James Almer

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.

(cherry picked from commit 99684f3ae752fc8bfb44a2dd1482f8d7a3d8536d)
Signed-off-by: James Almer <jamrial at gmail.com>

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

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

diff --git a/doc/APIchanges b/doc/APIchanges
index 7babf5babb..1e9b29fdbb 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2017-09-01 - xxxxxxx - lavf 57.80.100 / 57.11.0 - avio.h
+  Add avio_context_free(). From now on it must be used for freeing AVIOContext.
+
 2017-08-08 - xxxxxxx - lavu 55.74.100 - pixdesc.h
   Add AV_PIX_FMT_FLAG_FLOAT pixel format flag.
 
diff --git a/libavformat/avio.h b/libavformat/avio.h
index f14b003ba5..ea56dad503 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -467,6 +467,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 ec21fc7d38..716c42eda9 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -143,6 +143,11 @@ AVIOContext *avio_alloc_context(
     return s;
 }
 
+void avio_context_free(AVIOContext **ps)
+{
+    av_freep(ps);
+}
+
 static void writeout(AVIOContext *s, const uint8_t *data, int len)
 {
     if (!s->error) {
@@ -1123,7 +1128,9 @@ int avio_close(AVIOContext *s)
     else
         av_log(s, AV_LOG_DEBUG, "Statistics: %"PRId64" bytes read, %d seeks\n", s->bytes_read, s->seek_count);
     av_opt_free(s);
-    av_free(s);
+
+    avio_context_free(&s);
+
     return ffurl_close(h);
 }
 
@@ -1356,7 +1363,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;
 }
 
@@ -1399,6 +1408,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 3029a5e767..0af524c16b 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  57
-#define LIBAVFORMAT_VERSION_MINOR  79
+#define LIBAVFORMAT_VERSION_MINOR  80
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list