Browse Source

include: move realloc_or_free() with realloc_down()

pull/67/head
Rémi Denis-Courmont 9 years ago
parent
commit
20b486fa9e
  1. 15
      include/vlc_arrays.h
  2. 15
      include/vlc_memory.h

15
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; \

15
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;
}
/**
* @}

Loading…
Cancel
Save