[FFmpeg-cvslog] mem: Introduce av_reallocp

Luca Barbato git at videolan.org
Tue Sep 17 11:17:34 CEST 2013


ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Sun Sep 15 21:42:07 2013 +0200| [3feb3d6ce4be0a09a9f8f13d613bed25b523b6e7] | committer: Luca Barbato

mem: Introduce av_reallocp

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

 doc/APIchanges      |    3 +++
 libavutil/mem.c     |   16 ++++++++++++++++
 libavutil/mem.h     |   19 +++++++++++++++++++
 libavutil/version.h |    2 +-
 4 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 2b3b58d..58b6493 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:     2012-10-22
 
 API changes, most recent first:
 
+2013-09-xx - xxxxxxx - lavu 52.13.0 - mem.h
+  Add av_reallocp.
+
 2013-08-xx - xxxxxxx - lavc 55.16.0 - avcodec.h
   Extend AVPacket API with av_packet_unref, av_packet_ref,
   av_packet_move_ref, av_packet_copy_props, av_packet_free_side_data.
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 5f64f56..172180e 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -136,6 +136,22 @@ void *av_realloc(void *ptr, size_t size)
 #endif
 }
 
+int av_reallocp(void *ptr, size_t size)
+{
+    void **ptrptr = ptr;
+    void *ret;
+
+    ret = av_realloc(*ptrptr, size);
+
+    if (!ret) {
+        av_freep(ptr);
+        return AVERROR(ENOMEM);
+    }
+
+    *ptrptr = ret;
+    return 0;
+}
+
 void *av_realloc_array(void *ptr, size_t nmemb, size_t size)
 {
     if (!size || nmemb >= INT_MAX / size)
diff --git a/libavutil/mem.h b/libavutil/mem.h
index b473dd7..f51682b 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -117,6 +117,25 @@ av_alloc_size(1, 2) static inline void *av_malloc_array(size_t nmemb, size_t siz
 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
 
 /**
+ * Allocate or reallocate a block of memory.
+ * If *ptr is NULL and size > 0, allocate a new block. If
+ * size is zero, free the memory block pointed to by ptr.
+ * @param   ptr Pointer to a pointer to a memory block already allocated
+ *          with av_realloc(), or pointer to a pointer to NULL.
+ *          The pointer is updated on success, or freed on failure.
+ * @param   size Size in bytes for the memory block to be allocated or
+ *          reallocated
+ * @return  Zero on success, an AVERROR error code on failure.
+ * @warning Pointers originating from the av_malloc() family of functions must
+ *          not be passed to av_reallocp(). The former can be implemented using
+ *          memalign() (or other functions), and there is no guarantee that
+ *          pointers from such functions can be passed to realloc() at all.
+ *          The situation is undefined according to POSIX and may crash with
+ *          some libc implementations.
+ */
+int av_reallocp(void *ptr, size_t size);
+
+/**
  * Allocate or reallocate an array.
  * If ptr is NULL and nmemb > 0, allocate a new block. If
  * nmemb is zero, free the memory block pointed to by ptr.
diff --git a/libavutil/version.h b/libavutil/version.h
index c760d8d..935c505 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -37,7 +37,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 14
+#define LIBAVUTIL_VERSION_MINOR 15
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list