[vlc-commits] include: move realloc_or_free() with realloc_down()
Rémi Denis-Courmont
git at videolan.org
Sun Feb 11 20:38:47 CET 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Feb 11 21:35:16 2018 +0200| [20b486fa9edfdcc9a0b8533df133c6dd8dfdadbc] | committer: Rémi Denis-Courmont
include: move realloc_or_free() with realloc_down()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=20b486fa9edfdcc9a0b8533df133c6dd8dfdadbc
---
include/vlc_arrays.h | 15 +++++++++++++++
include/vlc_memory.h | 15 +--------------
2 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/include/vlc_arrays.h b/include/vlc_arrays.h
index 39b69952ff..b548ec2dc1 100644
--- a/include/vlc_arrays.h
+++ b/include/vlc_arrays.h
@@ -37,6 +37,21 @@ static inline void *realloc_down( void *ptr, size_t size )
return ret ? ret : ptr;
}
+/**
+ * This wrapper around realloc() will free the input pointer when
+ * realloc() returns NULL. The use case ptr = realloc(ptr, newsize) will
+ * cause a memory leak when ptr pointed to a heap allocation before,
+ * leaving the buffer allocated but unreferenced. vlc_realloc() is a
+ * drop-in replacement for that use case (and only that use case).
+ */
+static inline void *realloc_or_free( void *p, size_t sz )
+{
+ void *n = realloc(p,sz);
+ if( !n )
+ free(p);
+ return n;
+}
+
#define TAB_INIT( count, tab ) \
do { \
(count) = 0; \
diff --git a/include/vlc_memory.h b/include/vlc_memory.h
index 22ea0ea385..c53707e31b 100644
--- a/include/vlc_memory.h
+++ b/include/vlc_memory.h
@@ -32,20 +32,7 @@
* Memory fixups
*/
-/**
- * This wrapper around realloc() will free the input pointer when
- * realloc() returns NULL. The use case ptr = realloc(ptr, newsize) will
- * cause a memory leak when ptr pointed to a heap allocation before,
- * leaving the buffer allocated but unreferenced. vlc_realloc() is a
- * drop-in replacement for that use case (and only that use case).
- */
-static inline void *realloc_or_free( void *p, size_t sz )
-{
- void *n = realloc(p,sz);
- if( !n )
- free(p);
- return n;
-}
+
/**
* @}
More information about the vlc-commits
mailing list