1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#ifndef _MEMDEBUG_H_
#define _MEMDEBUG_H_
#include <stdlib.h>
#ifdef MEMDEBUG_TRACE
# define memdebug_trace(fmt, args...) \
({ \
fprintf(stderr, "*** " fmt " ***\n", ##args); \
fflush(stderr); \
})
#else
# define memdebug_trace(fmt, args...)
#endif
struct memdebug_heap_item {
struct memdebug_heap_item *next;
void *addr;
size_t size;
const char *func;
const char *file;
unsigned int line;
const char *freed_func;
const char *freed_file;
unsigned int freed_line;
};
#define memdebug_malloc(size) \
__memdebug_malloc(size, __func__, __FILE__, __LINE__)
#define memdebug_free(ptr) \
__memdebug_free(ptr, __func__, __FILE__, __LINE__)
void *__memdebug_malloc(size_t size, const char *func,
const char *file, const unsigned int line);
void __memdebug_free(void *ptr, const char *func,
const char *file, const unsigned int line);
void memdebug_report(int report_all);
#endif /* _MEMDEBUG_H_ */
|