Use tr_realloc (BSD reallocf-alike) instead of plain realloc

This commit is contained in:
Mike Gelfand 2015-10-25 17:13:14 +00:00
parent 57911bf349
commit f6f15d6937
4 changed files with 13 additions and 3 deletions

View File

@ -8,7 +8,6 @@
*/
#include <assert.h>
#include <stdlib.h> /* realloc () */
#include <string.h> /* memset */
#include "transmission.h"

View File

@ -8,7 +8,6 @@
*/
#include <assert.h>
#include <stdlib.h> /* tr_renew () -> realloc () */
#include <string.h> /* memmove */
#include "ptrarray.h"

View File

@ -129,6 +129,15 @@ tr_malloc0 (size_t size)
return size ? calloc (1, size) : NULL;
}
void *
tr_realloc (void * p, size_t size)
{
void * result = size != 0 ? realloc (p, size) : NULL;
if (result == NULL)
tr_free (p);
return result;
}
void
tr_free (void * p)
{

View File

@ -252,6 +252,9 @@ void* tr_malloc (size_t size);
/** @brief Portability wrapper around calloc () in which `0' is a safe argument */
void* tr_malloc0 (size_t size);
/** @brief Portability wrapper around reallocf () in which `0' is a safe argument */
void * tr_realloc (void * p, size_t size);
/** @brief Portability wrapper around free () in which `NULL' is a safe argument */
void tr_free (void * p);
@ -270,7 +273,7 @@ void* tr_memdup (const void * src, size_t byteCount);
((struct_type *) tr_malloc0 (sizeof (struct_type) * ((size_t)(n_structs))))
#define tr_renew(struct_type, mem, n_structs) \
((struct_type *) realloc ((mem), sizeof (struct_type) * ((size_t)(n_structs))))
((struct_type *) tr_realloc ((mem), sizeof (struct_type) * ((size_t)(n_structs))))
void* tr_valloc (size_t bufLen);