From ec7436a01deb8e28743de47ad98950c914d6da2a Mon Sep 17 00:00:00 2001
From: Christian C <cc@localhost>
Date: Tue, 1 Apr 2025 20:46:17 -0700
Subject: Global Allocator Checking

---
 lib/mem/galloc.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 lib/mem/galloc.c

(limited to 'lib/mem')

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; }
-- 
cgit v1.2.1