diff options
author | Christian C <cc@localhost> | 2025-04-01 20:46:17 -0700 |
---|---|---|
committer | Christian C <cc@localhost> | 2025-04-01 20:46:17 -0700 |
commit | ec7436a01deb8e28743de47ad98950c914d6da2a (patch) | |
tree | 765212b89d5c9740408d3d8bda8e1daacf55890e /lib/mem | |
parent | a18cea2fef7aa1545c9a984b60919541b26a6f84 (diff) |
Global Allocator Checking
Diffstat (limited to 'lib/mem')
-rw-r--r-- | lib/mem/galloc.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/mem/galloc.c b/lib/mem/galloc.c new file mode 100644 index 0000000..642e010 --- /dev/null +++ b/lib/mem/galloc.c @@ -0,0 +1,29 @@ +#include <lib/mem/galloc.h> +#include <stdlib.h> + +static ssize_t standing_allocations = 0; + +void *g_malloc(size_t size) { + void *ptr = malloc(size); + if (ptr == NULL) { + return ptr; + } + standing_allocations++; + return ptr; +} + +void *g_calloc(size_t n_memb, size_t size) { + void *ptr = calloc(n_memb, size); + if (ptr == NULL) { + return ptr; + } + standing_allocations++; + return ptr; +} + +void g_free(void *ptr) { + free(ptr); + standing_allocations--; +} + +ssize_t g_outstanding_allocations() { return standing_allocations; } |