#include #include #include static ssize_t standing_allocations = 0; void *_g_malloc(size_t size, char* file, unsigned int line) { void *ptr = malloc(size); if (ptr == NULL) { return ptr; } fprintf(stderr, "+%p :a: %s:%d\n", ptr, file, line); standing_allocations++; return ptr; } void *_g_calloc(size_t n_memb, size_t size, char* file, unsigned int line) { void *ptr = calloc(n_memb, size); if (ptr == NULL) { return ptr; } fprintf(stderr, "+%p :c: %s:%d\n", ptr, file, line); standing_allocations++; return ptr; } void *_g_realloc(void *ptr, size_t size, char* file, unsigned int line) { fprintf(stderr, "-%p :r: %s:%d\n", ptr, file, line); void* temp = realloc(ptr, size); if (temp == NULL) { fprintf(stderr, "+%p :r: %s:%d\n", ptr, file, line); } else { fprintf(stderr, "+%p :r: %s:%d\n", temp, file, line); } return temp; } void _g_free(void *ptr, char* file, unsigned int line) { if (ptr != NULL) { fprintf(stderr, "-%p :f: %s:%d\n", ptr, file, line); free(ptr); standing_allocations--; } } ssize_t g_outstanding_allocations() { return standing_allocations; }