00001 #ifndef XMEM_H
00002 #define XMEM_H
00003
00004
00005
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <sys/types.h>
00009
00011
00012
00013 #define xmem_on(p) do { xmem_config(1,1,1,1,100,1,0,0); xmem_reset(); } while(0)
00014
00015 #define xmem_off(p) xmem_config(0,0,0,0,100,0,0,0)
00016
00017
00018 #define xmem_malloc(size) xmem_domalloc_params((size), __FILE__, __LINE__)
00019
00020
00021 #define xmem_malloctype(type, n_elements) (type *)xmem_malloc((n_elements) * sizeof (type))
00022
00023
00024
00025 #define xmem_calloc(n_elements, size) xmem_calloc_params((n_elements), (size), __FILE__, __LINE__)
00026 #define xmem_calloctype(type, n_elements) (type *)xmem_calloc_params((n_elements), sizeof (type), __FILE__, __LINE__)
00027
00028
00029 #define xmem_free(ptr) do { xmem_dofree(ptr); ptr = NULL; } while(0)
00030
00031
00032 #define xmem_realloc(ptr, size) xmem_dorealloc_params((ptr), (size), __FILE__, __LINE__)
00033 #define xmem_realloctype(type, ptr, n_elements) (type *)xmem_realloc(ptr, ((n_elements) * sizeof (type)))
00034
00035
00036
00038 #ifdef XMEM_REPLACE_LIBC
00039 #undef malloc
00040 #undef calloc
00041 #undef free
00042 #undef realloc
00043 #undef strdup
00044
00045 #define malloc(size) xmem_domalloc_params((size), __FILE__, __LINE__)
00046 #define free(ptr) xmem_dofree(ptr)
00047 #define calloc(n_elements,size) xmem_calloc_params((n_elements), (size), __FILE__, __LINE__)
00048 #define realloc(ptr,size) xmem_dorealloc_params((ptr), (size), __FILE__, __LINE__)
00049 #define strdup(str) xmem_strdup_params((str), __FILE__, __LINE__)
00050 #endif
00051
00053
00054
00055
00056 void* xmem_domalloc_params(unsigned int size, const char *filename, int linenum);
00057
00058 void* xmem_domalloc_params(unsigned int size, const char *filename, int linenum);
00059 char *xmem_strdup_params(const char *str, const char *filename, int linenum);
00060
00061
00062 void *xmem_calloc_params(size_t n_elements, size_t size, const char * fname, int linenum);
00063
00064
00065 void xmem_dofree(void* ptr);
00066
00067
00068 int xmem_check_guardword(void *ptr);
00069
00070
00071
00072
00073
00074
00075 void* xmem_dorealloc_params(void* ptr, unsigned int size, const char *filename,
00076 int linenum);
00077
00079
00080
00081
00082 int xmem_leakcheck(void);
00083 void xmem_leakreport(void);
00084 int xmem_check_all_guardwords(FILE * fp, int maxlines);
00085
00086
00087 size_t xmem_usage(FILE * fp, int maxlines);
00088
00089
00090 size_t xmem_recenthighwater(void);
00091
00092
00093 void xmem_reset(void);
00094
00095
00096 void xmem_config(int memory_leak_locate, int trap_on_allocation, int replace_libc,
00097 int hang_on_out_of_mem, int report_length, int fill_with_nan,
00098 int assert_on_null_free, int warn_only);
00099
00100
00101
00102 #endif