Changeset 14592


Ignore:
Timestamp:
Oct 25, 2015, 5:13:14 PM (5 years ago)
Author:
mikedld
Message:

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

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bitfield.c

    r14532 r14592  
    99
    1010#include <assert.h>
    11 #include <stdlib.h> /* realloc () */
    1211#include <string.h> /* memset */
    1312
  • trunk/libtransmission/ptrarray.c

    r14241 r14592  
    99
    1010#include <assert.h>
    11 #include <stdlib.h> /* tr_renew () -> realloc () */
    1211#include <string.h> /* memmove */
    1312
  • trunk/libtransmission/utils.c

    r14588 r14592  
    128128{
    129129  return size ? calloc (1, size) : NULL;
     130}
     131
     132void *
     133tr_realloc (void * p, size_t size)
     134{
     135  void * result = size != 0 ? realloc (p, size) : NULL;
     136  if (result == NULL)
     137    tr_free (p);
     138  return result;
    130139}
    131140
  • trunk/libtransmission/utils.h

    r14588 r14592  
    253253void* tr_malloc0 (size_t size);
    254254
     255/** @brief Portability wrapper around reallocf () in which `0' is a safe argument */
     256void * tr_realloc (void * p, size_t size);
     257
    255258/** @brief Portability wrapper around free () in which `NULL' is a safe argument */
    256259void tr_free (void * p);
     
    271274
    272275#define tr_renew(struct_type, mem, n_structs)    \
    273   ((struct_type *) realloc ((mem), sizeof (struct_type) * ((size_t)(n_structs))))
     276  ((struct_type *) tr_realloc ((mem), sizeof (struct_type) * ((size_t)(n_structs))))
    274277
    275278void* tr_valloc (size_t bufLen);
Note: See TracChangeset for help on using the changeset viewer.