aboutsummaryrefslogtreecommitdiff
path: root/lib/mem/galloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mem/galloc.c')
-rw-r--r--lib/mem/galloc.c29
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; }