From 66788e6edb8a7e59f5676ca8cf928e23583cb31a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 7 Apr 2015 23:40:18 -0400 Subject: Implemented the memory logging. --- new/alloc_unix.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'new/alloc_unix.c') diff --git a/new/alloc_unix.c b/new/alloc_unix.c index f956bb2..238cf39 100644 --- a/new/alloc_unix.c +++ b/new/alloc_unix.c @@ -1,18 +1,36 @@ // 7 april 2015 +#include #include "uipriv_unix.h" -void *uiAlloc(size_t size) +void *uiAlloc(size_t size, const char *type) { - return g_malloc0(size); + void *out; + + out = g_malloc0(size); +#ifdef uiLogAllocations + fprintf(stderr, "%p alloc %s\n", out, type); +#endif + return out; } -void *uiRealloc(void *p, size_t size) +void *uiRealloc(void *p, size_t size, const char *type) { + void *out; + + if (p == NULL) + return uiAlloc(size, type); // TODO fill with 0s - return g_realloc(p, size); + out = g_realloc(p, size); +#ifdef uiLogAllocations + fprintf(stderr, "%p realloc %p\n", p, out); +#endif + return out; } void uiFree(void *p) { g_free(p); +#ifdef uiLogAllocations + fprintf(stderr, "%p free\n", p); +#endif } -- cgit v1.2.3