asterisk_malloc_debug.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2016 George Joseph <gjoseph@digium.com>
  3. *
  4. * See http://www.asterisk.org for more information about
  5. * the Asterisk project. Please do not directly contact
  6. * any of the maintainers of this project for assistance;
  7. * the project provides a web site, mailing lists and IRC
  8. * channels for your use.
  9. *
  10. * This program is free software, distributed under the terms of
  11. * the GNU General Public License Version 2. See the LICENSE file
  12. * at the top of the source tree.
  13. */
  14. #ifndef ASTERISK_MALLOC_DEBUG_H_
  15. #define ASTERISK_MALLOC_DEBUG_H_
  16. /* Include these now to prevent them from messing up MALLOC_DEBUG */
  17. #include <sys/types.h>
  18. #include <pj/compat/string.h>
  19. #include <pj/compat/stdarg.h>
  20. #include <pj/compat/malloc.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
  25. __attribute__((format(printf, 5, 6)));
  26. void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
  27. void __ast_free(void *ptr, const char *file, int lineno, const char *func);
  28. void *__ast_malloc(size_t size, const char *file, int lineno, const char *func);
  29. void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
  30. char *__ast_strdup(const char *s, const char *file, int lineno, const char *func);
  31. char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);
  32. int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
  33. __attribute__((format(printf, 2, 0)));
  34. /* Undefine any macros */
  35. #undef asprintf
  36. #undef calloc
  37. #undef free
  38. #undef malloc
  39. #undef realloc
  40. #undef strdup
  41. #undef strndup
  42. #undef vasprintf
  43. /* Provide our own definitions */
  44. #define asprintf(a, b, c...) \
  45. __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
  46. #define calloc(a,b) \
  47. __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  48. #define free(a) \
  49. __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  50. #define malloc(a) \
  51. __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  52. #define realloc(a,b) \
  53. __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  54. #define strdup(a) \
  55. __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  56. #define strndup(a,b) \
  57. __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  58. #define vasprintf(a,b,c) \
  59. __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63. #endif /* ASTERISK_MALLOC_DEBUG_H_ */