| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#ifndef ASTERISK_MALLOC_DEBUG_H_ |
| 16 |
#define ASTERISK_MALLOC_DEBUG_H_ |
| 17 |
|
| 18 |
|
| 19 |
#include <sys/types.h> |
| 20 |
#include <pj/compat/string.h> |
| 21 |
#include <pj/compat/stdarg.h> |
| 22 |
#include <pj/compat/malloc.h> |
| 23 |
|
| 24 |
#ifdef __cplusplus |
| 25 |
extern "C" { |
| 26 |
#endif |
| 27 |
|
| 28 |
#ifndef attribute_malloc |
| 29 |
#ifdef HAVE_ATTRIBUTE_malloc |
| 30 |
|
| 31 |
|
| 32 |
#define attribute_malloc __attribute__((malloc)) |
| 33 |
#else |
| 34 |
#define attribute_malloc |
| 35 |
#endif |
| 36 |
#endif |
| 37 |
|
| 38 |
int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...) |
| 39 |
__attribute__((format(printf, 5, 6))); |
| 40 |
void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc; |
| 41 |
void __ast_free(void *ptr, const char *file, int lineno, const char *func); |
| 42 |
void *__ast_repl_malloc(size_t size, const char *file, int lineno, const char *func) attribute_malloc; |
| 43 |
void *__ast_repl_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func); |
| 44 |
char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func) attribute_malloc; |
| 45 |
char *__ast_repl_strndup(const char *s, size_t n, const char *file, int lineno, const char *func) attribute_malloc; |
| 46 |
int __ast_repl_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func) |
| 47 |
__attribute__((format(printf, 2, 0))); |
| 48 |
|
| 49 |
|
| 50 |
#undef asprintf |
| 51 |
#undef calloc |
| 52 |
#undef free |
| 53 |
#undef malloc |
| 54 |
#undef realloc |
| 55 |
#undef strdup |
| 56 |
#undef strndup |
| 57 |
#undef vasprintf |
| 58 |
|
| 59 |
|
| 60 |
#define asprintf(strp, format, args...) \ |
| 61 |
__ast_repl_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, strp, format, args) |
| 62 |
|
| 63 |
#define calloc(nmemb, size) \ |
| 64 |
__ast_repl_calloc(nmemb, size, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| 65 |
|
| 66 |
#define free(ptr) \ |
| 67 |
__ast_free(ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| 68 |
|
| 69 |
#define malloc(size) \ |
| 70 |
__ast_repl_malloc(size, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| 71 |
|
| 72 |
#define realloc(ptr, size) \ |
| 73 |
__ast_repl_realloc(ptr, size, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| 74 |
|
| 75 |
#define strdup(s) \ |
| 76 |
__ast_repl_strdup(s, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| 77 |
|
| 78 |
#define strndup(s, n) \ |
| 79 |
__ast_repl_strndup(s, n, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| 80 |
|
| 81 |
#define vasprintf(strp, format, ap) \ |
| 82 |
__ast_repl_vasprintf(strp, format, ap, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
| 83 |
|
| 84 |
#ifdef __cplusplus |
| 85 |
} |
| 86 |
#endif |
| 87 |
|
| 88 |
#endif |