[FFmpeg-devel] [PATCH 1/2] avutil/mem: Add av_fast_mallocz()
Michael Niedermayer
michaelni at gmx.at
Wed Nov 18 14:41:04 CET 2015
From: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
libavutil/mem.c | 4 ++++
libavutil/mem.h | 15 +++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 323b183..8dfaad8 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -501,3 +501,7 @@ void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
ff_fast_malloc(ptr, size, min_size, 0);
}
+void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
+{
+ ff_fast_malloc(ptr, size, min_size, 1);
+}
diff --git a/libavutil/mem.h b/libavutil/mem.h
index a8eb14e..d25b322 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -385,6 +385,21 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
/**
+ * Allocate a buffer, reusing the given one if large enough.
+ *
+ * All newly allocated space is initially cleared
+ * Contrary to av_fast_realloc the current buffer contents might not be
+ * preserved and on error the old buffer is freed, thus no special
+ * handling to avoid memleaks is necessary.
+ *
+ * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer
+ * @param size size of the buffer *ptr points to
+ * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
+ * *size 0 if an error occurred.
+ */
+void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size);
+
+/**
* @}
*/
--
1.7.9.5
More information about the ffmpeg-devel
mailing list