| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: MemLeakFinder.h |
|---|
| 5 | // Purpose: Memory leak finder |
|---|
| 6 | // Created: 12/1/04 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #ifndef MEMLEAKFINDER__H |
|---|
| 11 | #define MEMLEAKFINDER__H |
|---|
| 12 | |
|---|
| 13 | #ifdef MEMLEAKFINDER_FULL_MALLOC_MONITORING |
|---|
| 14 | // include stdlib now, to avoid problems with having the macros defined already |
|---|
| 15 | #include <cstdlib> |
|---|
| 16 | #endif |
|---|
| 17 | |
|---|
| 18 | // global enable flag |
|---|
| 19 | extern bool memleakfinder_global_enable; |
|---|
| 20 | |
|---|
| 21 | class MemLeakSuppressionGuard |
|---|
| 22 | { |
|---|
| 23 | public: |
|---|
| 24 | MemLeakSuppressionGuard(); |
|---|
| 25 | ~MemLeakSuppressionGuard(); |
|---|
| 26 | }; |
|---|
| 27 | |
|---|
| 28 | extern "C" |
|---|
| 29 | { |
|---|
| 30 | void *memleakfinder_malloc(size_t size, const char *file, int line); |
|---|
| 31 | void *memleakfinder_realloc(void *ptr, size_t size); |
|---|
| 32 | void memleakfinder_free(void *ptr); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | void memleakfinder_init(); |
|---|
| 36 | |
|---|
| 37 | int memleakfinder_numleaks(); |
|---|
| 38 | |
|---|
| 39 | void memleakfinder_reportleaks(); |
|---|
| 40 | |
|---|
| 41 | void memleakfinder_reportleaks_appendfile(const char *filename, const char *markertext); |
|---|
| 42 | |
|---|
| 43 | void memleakfinder_setup_exit_report(const char *filename, const char *markertext); |
|---|
| 44 | |
|---|
| 45 | void memleakfinder_startsectionmonitor(); |
|---|
| 46 | |
|---|
| 47 | void memleakfinder_traceblocksinsection(); |
|---|
| 48 | |
|---|
| 49 | void memleakfinder_notaleak(void *ptr); |
|---|
| 50 | |
|---|
| 51 | void *operator new (size_t size, const char *file, int line); |
|---|
| 52 | void *operator new[](size_t size, const char *file, int line); |
|---|
| 53 | |
|---|
| 54 | // define the malloc functions now, if required |
|---|
| 55 | #ifdef MEMLEAKFINDER_FULL_MALLOC_MONITORING |
|---|
| 56 | #define malloc(X) memleakfinder_malloc(X, __FILE__, __LINE__) |
|---|
| 57 | #define realloc memleakfinder_realloc |
|---|
| 58 | #define free memleakfinder_free |
|---|
| 59 | #define MEMLEAKFINDER_MALLOC_MONITORING_DEFINED |
|---|
| 60 | #endif |
|---|
| 61 | |
|---|
| 62 | #endif // MEMLEAKFINDER__H |
|---|
| 63 | |
|---|