00001
00002 #ifndef _MALLOC_H_
00003 #define _MALLOC_H_
00004
00005 #include <config.h>
00006 #include <stdlib.h>
00007
00008 #ifdef __LEAK_TRACER
00009
00010 void *internal_malloc(size_t size, char *file, int line);
00011 void *internal_calloc(size_t size, char *file, int line);
00012 void *internal_realloc(void *old, size_t size, char *file, int line);
00013 void internal_free(void *ptr, char *file, int line);
00014
00015 #define MALLOC(result, type, number) result = (type *)internal_malloc((number) * sizeof(type), __FILE__, __LINE__)
00016 #define CALLOC(result, type, number) result = (type *)internal_calloc((number) * sizeof(type), __FILE__, __LINE__)
00017 #define REALLOC(result, type, number) result = (type *)internal_realloc(result, (number) * sizeof(type), __FILE__, __LINE__)
00018 #define FREE(result) if (result != NULL) internal_free(result, __FILE__, __LINE__), result = NULL
00019
00020 #else
00021
00022 #define MALLOC(result, type, number) if (!((result) = (type *)malloc((number) * sizeof(type)))) \
00023 printf("SYSERR: malloc failure at %s:%d.\n", __FILE__, __LINE__), abort()
00024
00025 #define CALLOC(result, type, number) if (!((result) = (type *)calloc((number), sizeof(type)))) \
00026 printf("SYSERR: calloc failure at %s:%d.\n", __FILE__, __LINE__), abort()
00027
00028 #define REALLOC(result, type, number) if (!((result) = (type *)realloc((result), sizeof(type) * (number)))) \
00029 printf("SYSERR: realloc failure at %s:%d.\n", __FILE__, __LINE__), abort()
00030
00031 #define FREE(result) if (result) free(result), result = NULL
00032
00033 #endif
00034
00035 #endif // _MALLOC_H_