Wed Jan 8 2020 09:49:42

Asterisk developer's documentation


astmm.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2006, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  * \brief Asterisk memory usage debugging
21  * This file provides headers for MALLOC_DEBUG, a define used for tracking down
22  * memory leaks. It should never be \#included directly; always use the
23  * MALLOC_DEBUG definition in menuselect to activate those functions.
24  */
25 
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #ifndef _ASTERISK_ASTMM_H
32 #define _ASTERISK_ASTMM_H
33 
34 #ifndef STANDALONE
35 
36 #define __AST_DEBUG_MALLOC
37 
38 #include "asterisk.h"
39 
40 /* Include these now to prevent them from being needed later */
41 #include <sys/types.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <stdio.h>
45 #include <stdarg.h>
46 
47 /* Undefine any macros */
48 #undef malloc
49 #undef calloc
50 #undef realloc
51 #undef strdup
52 #undef strndup
53 #undef asprintf
54 #undef vasprintf
55 #undef free
56 
57 void *ast_std_malloc(size_t size);
58 void *ast_std_calloc(size_t nmemb, size_t size);
59 void *ast_std_realloc(void *ptr, size_t size);
60 void ast_std_free(void *ptr);
61 void ast_free_ptr(void *ptr);
62 
63 void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
64 void *__ast_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
65 void *__ast_malloc(size_t size, const char *file, int lineno, const char *func);
66 void __ast_free(void *ptr, const char *file, int lineno, const char *func);
67 void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
68 char *__ast_strdup(const char *s, const char *file, int lineno, const char *func);
69 char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);
70 int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
71  __attribute__((format(printf, 5, 6)));
72 int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
73  __attribute__((format(printf, 2, 0)));
74 void __ast_mm_init_phase_1(void);
75 void __ast_mm_init_phase_2(void);
76 
77 
78 /* Provide our own definitions */
79 #define calloc(a,b) \
80  __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
81 
82 #define ast_calloc(a,b) \
83  __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
84 
85 #define ast_calloc_cache(a,b) \
86  __ast_calloc_cache(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
87 
88 #define malloc(a) \
89  __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
90 
91 #define ast_malloc(a) \
92  __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
93 
94 #define free(a) \
95  __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
96 
97 #define ast_free(a) \
98  __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
99 
100 #define realloc(a,b) \
101  __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
102 
103 #define ast_realloc(a,b) \
104  __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
105 
106 #define strdup(a) \
107  __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
108 
109 #define ast_strdup(a) \
110  __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
111 
112 #define strndup(a,b) \
113  __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
114 
115 #define ast_strndup(a,b) \
116  __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
117 
118 #define asprintf(a, b, c...) \
119  __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
120 
121 #define ast_asprintf(a, b, c...) \
122  __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
123 
124 #define vasprintf(a,b,c) \
125  __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
126 
127 #define ast_vasprintf(a,b,c) \
128  __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
129 
130 #endif /* !STANDALONE */
131 
132 #else
133 #error "NEVER INCLUDE astmm.h DIRECTLY!!"
134 #endif /* _ASTERISK_ASTMM_H */
135 
136 #ifdef __cplusplus
137 }
138 #endif
void ast_std_free(void *ptr)
Asterisk main include file. File version handling, generic pbx functions.
void * __ast_malloc(size_t size, const char *file, int lineno, const char *func)
char * __ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)
void __ast_free(void *ptr, const char *file, int lineno, const char *func)
void * ast_std_realloc(void *ptr, size_t size)
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
void * ast_std_malloc(size_t size)
void ast_free_ptr(void *ptr)
int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
void __ast_mm_init_phase_1(void)
char * __ast_strdup(const char *s, const char *file, int lineno, const char *func)
void * __ast_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
void * __ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)
void * ast_std_calloc(size_t nmemb, size_t size)
void __ast_mm_init_phase_2(void)
static snd_pcm_format_t format
Definition: chan_alsa.c:93
int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format,...)