aboutsummaryrefslogtreecommitdiff
path: root/lib/mem/galloc.c
blob: 642e010f36be690b10dcba3b85af90853ca8b52b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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; }