#include "aplwc_repl.h" static uint64_t malloc_count = 0; static uint64_t malloc_fail_after(void) { #if APLWC_BUILD_TYPE_RELEASE return UINT64_MAX; #else static int setup; static uint64_t count, count_rec; if(!setup){ setup = 1; count = getenv_ulong("APLWC_MALLOC_FAIL_AFTER", ULONG_MAX); count_rec = malloc_fail_after(); assert(ALWAYS(count == count_rec)); } return count; #endif } #undef malloc void * wrapped_malloc(size_t size) { if(malloc_count++ >= malloc_fail_after()) return NULL; else return malloc(size); } #undef free void wrapped_free(void *ptr) { free(ptr); }