[09/12] avio: Add an internal utility function for freeing dynamic buffers

Message ID 1424795718-79013-9-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö Feb. 24, 2015, 4:35 p.m.
---
 libavformat/avio_internal.h |  7 +++++++
 libavformat/aviobuf.c       | 10 ++++++++++
 2 files changed, 17 insertions(+)

Comments

Diego Biurrun Feb. 24, 2015, 5:33 p.m. | #1
On Tue, Feb 24, 2015 at 06:35:15PM +0200, Martin Storsjö wrote:
> --- a/libavformat/avio_internal.h
> +++ b/libavformat/avio_internal.h
> @@ -139,4 +139,11 @@ int ffio_open_null_buf(AVIOContext **s);
>  
> +/**
> + * Free a dynamic buffer.
> + *
> + * @param s a pointer to an IO context opened by avio_open_dyn_buf

I think Doxygen creates an internal link to the function if you append ().

LGTM

Diego

Patch

diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
index a8bcadd..5d00151 100644
--- a/libavformat/avio_internal.h
+++ b/libavformat/avio_internal.h
@@ -139,4 +139,11 @@  int ffio_open_null_buf(AVIOContext **s);
  */
 int ffio_close_null_buf(AVIOContext *s);
 
+/**
+ * Free a dynamic buffer.
+ *
+ * @param s a pointer to an IO context opened by avio_open_dyn_buf
+ */
+void ffio_free_dyn_buf(AVIOContext **s);
+
 #endif /* AVFORMAT_AVIO_INTERNAL_H */
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 5f848b2..8dc805a 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -991,6 +991,16 @@  int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
     return size - padding;
 }
 
+void ffio_free_dyn_buf(AVIOContext **s)
+{
+    uint8_t *tmp;
+    if (!*s)
+        return;
+    avio_close_dyn_buf(*s, &tmp);
+    av_free(tmp);
+    *s = NULL;
+}
+
 static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
 {
     DynBuffer *d = opaque;