1 #include "malloc_wrappers.h"
6 static size_t alloc_count = 0;
8 /* Allocate memory and place check values before and after. */
9 void* malloc_with_check(size_t size)
11 size_t size32 = (size + 3) / 4 + 3;
12 uint32_t *buf = malloc(size32 * sizeof(uint32_t));
15 buf[size32 - 1] = 0xBADBAD;
19 /* Free memory allocated with malloc_with_check() and do the checks. */
20 void free_with_check(void *mem)
22 uint32_t *buf = (uint32_t*)mem - 2;
23 assert(buf[1] == 0xDEADBEEF);
24 assert(buf[buf[0] - 1] == 0xBADBAD);
28 /* Track memory usage */
29 void* counting_realloc(void *ptr, size_t size)
31 /* Don't allocate crazy amounts of RAM when fuzzing */
38 return realloc(ptr, size);
41 void counting_free(void *ptr)
45 assert(alloc_count > 0);
51 size_t get_alloc_count()