#include "noleak.h" #include static void *___noleak_data = NULL; static size_t ___noleak_capacity = 0; static size_t ___noleak_used = 0; int noleak_init(size_t capacity) { ___noleak_data = calloc(1, capacity); if (___noleak_data == NULL) return 1; ___noleak_capacity = capacity; return 0; } void noleak_deinit(void) { if (___noleak_data != NULL) { free(___noleak_data); ___noleak_data = NULL; } } void *noleak_alloc(size_t size) { if (___noleak_data == NULL) return NULL; if (___noleak_used + size >= ___noleak_capacity) return NULL; void *const ptr = ___noleak_data + ___noleak_used; ___noleak_used += size; return ptr; }