11 #ifndef TOR_UTIL_MALLOC_H
12 #define TOR_UTIL_MALLOC_H
21 void *
tor_calloc_(
size_t nmemb,
size_t size) ATTR_MALLOC;
46 #define tor_free(p) STMT_BEGIN \
47 typeof(&(p)) tor_free__tmpvar = &(p); \
48 raw_free(*tor_free__tmpvar); \
49 *tor_free__tmpvar=NULL; \
52 #define tor_free(p) STMT_BEGIN \
58 #define tor_malloc(size) tor_malloc_(size)
59 #define tor_malloc_zero(size) tor_malloc_zero_(size)
60 #define tor_calloc(nmemb,size) tor_calloc_(nmemb, size)
61 #define tor_realloc(ptr, size) tor_realloc_(ptr, size)
62 #define tor_reallocarray(ptr, sz1, sz2) \
63 tor_reallocarray_((ptr), (sz1), (sz2))
64 #define tor_strdup(s) tor_strdup_(s)
65 #define tor_strndup(s, n) tor_strndup_(s, n)
66 #define tor_memdup(s, n) tor_memdup_(s, n)
67 #define tor_memdup_nulterm(s, n) tor_memdup_nulterm_(s, n)
72 #define raw_malloc malloc
73 #define raw_realloc realloc
75 #define raw_strdup strdup
80 #define FREE_AND_NULL(typename, freefn, var) \
83 typename **tmp__free__ptr ## freefn = &(var); \
84 freefn(*tmp__free__ptr ## freefn); \
85 (*tmp__free__ptr ## freefn) = NULL; \
88 #ifdef UTIL_MALLOC_PRIVATE
Utility macros to handle different features and behavior in different compilers.
STATIC int size_mul_check(const size_t x, const size_t y)
void * tor_memdup_(const void *mem, size_t len) ATTR_MALLOC
void * tor_reallocarray_(void *ptr, size_t size1, size_t size2)
void tor_free_(void *mem)
void * tor_realloc_(void *ptr, size_t size)
void * tor_memdup_nulterm_(const void *mem, size_t len) ATTR_MALLOC
char * tor_strndup_(const char *s, size_t n) ATTR_MALLOC
char * tor_strdup_(const char *s) ATTR_MALLOC
void * tor_calloc_(size_t nmemb, size_t size) ATTR_MALLOC
void * tor_malloc_zero_(size_t size) ATTR_MALLOC
void * tor_malloc_(size_t size) ATTR_MALLOC