18 #define UTIL_MALLOC_PRIVATE
23 #ifdef __clang_analyzer__
24 #undef MALLOC_ZERO_WORKS
38 #ifndef MALLOC_ZERO_WORKS
45 result = raw_malloc(size);
47 if (PREDICT_UNLIKELY(result == NULL)) {
52 raw_assert_unreached_msg(
"Out of memory on malloc(). Dying.");
72 memset(result, 0, size);
81 #define SQRT_SIZE_MAX_P1 (((size_t)1) << (sizeof(size_t)*4))
94 return ((x|y) < SQRT_SIZE_MAX_P1 ||
124 #ifndef MALLOC_ZERO_WORKS
131 result = raw_realloc(ptr, size);
133 if (PREDICT_UNLIKELY(result == NULL)) {
135 raw_assert_unreached_msg(
"Out of memory on realloc(). Dying.");
152 return tor_realloc(ptr, (sz1 * sz2));
165 duplicate = raw_strdup(s);
167 if (PREDICT_UNLIKELY(duplicate == NULL)) {
169 raw_assert_unreached_msg(
"Out of memory on strdup(). Dying.");
192 strncpy(duplicate, s, n);
206 memcpy(duplicate, mem, len);
219 memcpy(duplicate, mem, len);
220 duplicate[len] =
'\0';
void * tor_calloc_(size_t nmemb, size_t size)
char * tor_strndup_(const char *s, size_t n)
void * tor_malloc_zero_(size_t size)
void * tor_memdup_(const void *mem, size_t len)
char * tor_strdup_(const char *s)
void tor_free_(void *mem)
STATIC int size_mul_check(const size_t x, const size_t y)
void * tor_realloc_(void *ptr, size_t size)
void * tor_memdup_nulterm_(const void *mem, size_t len)
void * tor_reallocarray_(void *ptr, size_t sz1, size_t sz2)
void * tor_malloc_(size_t size)
Headers for util_malloc.c.
Macros to implement mocking and selective exposure for the test code.
Integer definitions used throughout Tor.