mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 04:11:08 +00:00
core: Improve MALLOC_DEBUG for frames.
* Pass caller information to frame allocation functions. * Disable caching as it interfers with MALLOC_DEBUG reporting. * Stop using ast_calloc_cache. Change-Id: Id343cd80a3db941d2daefde2a060750fea8cd260
This commit is contained in:
@@ -24,6 +24,8 @@ ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
$(call MOD_ADD_C,chan_iax2,$(wildcard iax2/*.c))
|
$(call MOD_ADD_C,chan_iax2,$(wildcard iax2/*.c))
|
||||||
|
iax2/parser.o: _ASTCFLAGS+=$(call get_menuselect_cflags,MALLOC_DEBUG)
|
||||||
|
|
||||||
$(call MOD_ADD_C,chan_sip,$(wildcard sip/*.c))
|
$(call MOD_ADD_C,chan_sip,$(wildcard sip/*.c))
|
||||||
$(call MOD_ADD_C,chan_pjsip,$(wildcard pjsip/*.c))
|
$(call MOD_ADD_C,chan_pjsip,$(wildcard pjsip/*.c))
|
||||||
$(call MOD_ADD_C,chan_dahdi,$(wildcard dahdi/*.c) sig_analog.c sig_pri.c sig_ss7.c)
|
$(call MOD_ADD_C,chan_dahdi,$(wildcard dahdi/*.c) sig_analog.c sig_pri.c sig_ss7.c)
|
||||||
|
@@ -52,7 +52,11 @@ static int frames = 0;
|
|||||||
static int iframes = 0;
|
static int iframes = 0;
|
||||||
static int oframes = 0;
|
static int oframes = 0;
|
||||||
|
|
||||||
#if !defined(LOW_MEMORY)
|
#if (defined(LOW_MEMORY) || defined(MALLOC_DEBUG)) && !defined(NO_FRAME_CACHE)
|
||||||
|
#define NO_FRAME_CACHE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(NO_FRAME_CACHE)
|
||||||
static void frame_cache_cleanup(void *data);
|
static void frame_cache_cleanup(void *data);
|
||||||
|
|
||||||
/*! \brief A per-thread cache of iax_frame structures */
|
/*! \brief A per-thread cache of iax_frame structures */
|
||||||
@@ -1215,7 +1219,7 @@ struct iax_frame *iax_frame_new(int direction, int datalen, unsigned int cacheab
|
|||||||
{
|
{
|
||||||
struct iax_frame *fr;
|
struct iax_frame *fr;
|
||||||
|
|
||||||
#if !defined(LOW_MEMORY)
|
#if !defined(NO_FRAME_CACHE)
|
||||||
if (cacheable) {
|
if (cacheable) {
|
||||||
struct iax_frames *iax_frames;
|
struct iax_frames *iax_frames;
|
||||||
struct iax_frame *smallest;
|
struct iax_frame *smallest;
|
||||||
@@ -1243,13 +1247,13 @@ struct iax_frame *iax_frame_new(int direction, int datalen, unsigned int cacheab
|
|||||||
iax_frames->size--;
|
iax_frames->size--;
|
||||||
ast_free(smallest);
|
ast_free(smallest);
|
||||||
}
|
}
|
||||||
if (!(fr = ast_calloc_cache(1, sizeof(*fr) + datalen))) {
|
if (!(fr = ast_calloc(1, sizeof(*fr) + datalen))) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fr->afdatalen = datalen;
|
fr->afdatalen = datalen;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!(fr = ast_calloc_cache(1, sizeof(*fr) + datalen))) {
|
if (!(fr = ast_calloc(1, sizeof(*fr) + datalen))) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fr->afdatalen = datalen;
|
fr->afdatalen = datalen;
|
||||||
@@ -1280,7 +1284,7 @@ struct iax_frame *iax_frame_new(int direction, int datalen, unsigned int cacheab
|
|||||||
|
|
||||||
void iax_frame_free(struct iax_frame *fr)
|
void iax_frame_free(struct iax_frame *fr)
|
||||||
{
|
{
|
||||||
#if !defined(LOW_MEMORY)
|
#if !defined(NO_FRAME_CACHE)
|
||||||
struct iax_frames *iax_frames = NULL;
|
struct iax_frames *iax_frames = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1295,7 +1299,7 @@ void iax_frame_free(struct iax_frame *fr)
|
|||||||
}
|
}
|
||||||
ast_atomic_fetchadd_int(&frames, -1);
|
ast_atomic_fetchadd_int(&frames, -1);
|
||||||
|
|
||||||
#if !defined(LOW_MEMORY)
|
#if !defined(NO_FRAME_CACHE)
|
||||||
if (!fr->cacheable
|
if (!fr->cacheable
|
||||||
|| !ast_opt_cache_media_frames
|
|| !ast_opt_cache_media_frames
|
||||||
|| !(iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
|
|| !(iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
|
||||||
@@ -1319,7 +1323,7 @@ void iax_frame_free(struct iax_frame *fr)
|
|||||||
ast_free(fr);
|
ast_free(fr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(LOW_MEMORY)
|
#if !defined(NO_FRAME_CACHE)
|
||||||
static void frame_cache_cleanup(void *data)
|
static void frame_cache_cleanup(void *data)
|
||||||
{
|
{
|
||||||
struct iax_frames *framelist = data;
|
struct iax_frames *framelist = data;
|
||||||
|
@@ -560,14 +560,16 @@ void ast_frame_dtor(struct ast_frame *frame);
|
|||||||
* should be the last operation you do with that frame before freeing
|
* should be the last operation you do with that frame before freeing
|
||||||
* it (or exiting the block, if the frame is on the stack.)
|
* it (or exiting the block, if the frame is on the stack.)
|
||||||
*/
|
*/
|
||||||
struct ast_frame *ast_frisolate(struct ast_frame *fr);
|
#define ast_frisolate(fr) __ast_frisolate(fr, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
||||||
|
struct ast_frame *__ast_frisolate(struct ast_frame *fr, const char *file, int line, const char *func);
|
||||||
|
|
||||||
/*! \brief Copies a frame
|
/*! \brief Copies a frame
|
||||||
* \param fr frame to copy
|
* \param fr frame to copy
|
||||||
* Duplicates a frame -- should only rarely be used, typically frisolate is good enough
|
* Duplicates a frame -- should only rarely be used, typically frisolate is good enough
|
||||||
* \return Returns a frame on success, NULL on error
|
* \return Returns a frame on success, NULL on error
|
||||||
*/
|
*/
|
||||||
struct ast_frame *ast_frdup(const struct ast_frame *fr);
|
#define ast_frdup(fr) __ast_frdup(fr, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
||||||
|
struct ast_frame *__ast_frdup(const struct ast_frame *fr, const char *file, int line, const char *func);
|
||||||
|
|
||||||
void ast_swapcopy_samples(void *dst, const void *src, int samples);
|
void ast_swapcopy_samples(void *dst, const void *src, int samples);
|
||||||
|
|
||||||
|
@@ -159,6 +159,7 @@ cdr.o: _ASTCFLAGS+=$(AST_NO_FORMAT_TRUNCATION)
|
|||||||
crypt.o: _ASTCFLAGS+=$(CRYPT_INCLUDE)
|
crypt.o: _ASTCFLAGS+=$(CRYPT_INCLUDE)
|
||||||
db.o: _ASTCFLAGS+=$(SQLITE3_INCLUDE)
|
db.o: _ASTCFLAGS+=$(SQLITE3_INCLUDE)
|
||||||
dsp.o: _ASTCFLAGS+=$(call get_menuselect_cflags,RADIO_RELAX)
|
dsp.o: _ASTCFLAGS+=$(call get_menuselect_cflags,RADIO_RELAX)
|
||||||
|
frame.o: _ASTCFLAGS+=$(call get_menuselect_cflags,MALLOC_DEBUG)
|
||||||
http.o: _ASTCFLAGS+=$(GMIMECFLAGS)
|
http.o: _ASTCFLAGS+=$(GMIMECFLAGS)
|
||||||
iostream.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)
|
iostream.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)
|
||||||
json.o: _ASTCFLAGS+=$(JANSSON_INCLUDE)
|
json.o: _ASTCFLAGS+=$(JANSSON_INCLUDE)
|
||||||
|
37
main/frame.c
37
main/frame.c
@@ -43,7 +43,11 @@
|
|||||||
#include "asterisk/dsp.h"
|
#include "asterisk/dsp.h"
|
||||||
#include "asterisk/file.h"
|
#include "asterisk/file.h"
|
||||||
|
|
||||||
#if !defined(LOW_MEMORY)
|
#if (defined(LOW_MEMORY) || defined(MALLOC_DEBUG)) && !defined(NO_FRAME_CACHE)
|
||||||
|
#define NO_FRAME_CACHE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(NO_FRAME_CACHE)
|
||||||
static void frame_cache_cleanup(void *data);
|
static void frame_cache_cleanup(void *data);
|
||||||
|
|
||||||
/*! \brief A per-thread cache of frame headers */
|
/*! \brief A per-thread cache of frame headers */
|
||||||
@@ -72,11 +76,11 @@ struct ast_frame_cache {
|
|||||||
|
|
||||||
struct ast_frame ast_null_frame = { AST_FRAME_NULL, };
|
struct ast_frame ast_null_frame = { AST_FRAME_NULL, };
|
||||||
|
|
||||||
static struct ast_frame *ast_frame_header_new(void)
|
static struct ast_frame *ast_frame_header_new(const char *file, int line, const char *func)
|
||||||
{
|
{
|
||||||
struct ast_frame *f;
|
struct ast_frame *f;
|
||||||
|
|
||||||
#if !defined(LOW_MEMORY)
|
#if !defined(NO_FRAME_CACHE)
|
||||||
struct ast_frame_cache *frames;
|
struct ast_frame_cache *frames;
|
||||||
|
|
||||||
if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames)))) {
|
if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames)))) {
|
||||||
@@ -89,19 +93,18 @@ static struct ast_frame *ast_frame_header_new(void)
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(f = ast_calloc_cache(1, sizeof(*f))))
|
|
||||||
return NULL;
|
|
||||||
#else
|
|
||||||
if (!(f = ast_calloc(1, sizeof(*f))))
|
|
||||||
return NULL;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!(f = __ast_calloc(1, sizeof(*f), file, line, func))) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
f->mallocd_hdr_len = sizeof(*f);
|
f->mallocd_hdr_len = sizeof(*f);
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(LOW_MEMORY)
|
#if !defined(NO_FRAME_CACHE)
|
||||||
static void frame_cache_cleanup(void *data)
|
static void frame_cache_cleanup(void *data)
|
||||||
{
|
{
|
||||||
struct ast_frame_cache *frames = data;
|
struct ast_frame_cache *frames = data;
|
||||||
@@ -119,7 +122,7 @@ static void __frame_free(struct ast_frame *fr, int cache)
|
|||||||
if (!fr->mallocd)
|
if (!fr->mallocd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#if !defined(LOW_MEMORY)
|
#if !defined(NO_FRAME_CACHE)
|
||||||
if (fr->mallocd == AST_MALLOCD_HDR
|
if (fr->mallocd == AST_MALLOCD_HDR
|
||||||
&& cache
|
&& cache
|
||||||
&& ast_opt_cache_media_frames) {
|
&& ast_opt_cache_media_frames) {
|
||||||
@@ -185,7 +188,7 @@ void ast_frame_dtor(struct ast_frame *f)
|
|||||||
* (header, src, data).
|
* (header, src, data).
|
||||||
* On return all components are malloc'ed
|
* On return all components are malloc'ed
|
||||||
*/
|
*/
|
||||||
struct ast_frame *ast_frisolate(struct ast_frame *fr)
|
struct ast_frame *__ast_frisolate(struct ast_frame *fr, const char *file, int line, const char *func)
|
||||||
{
|
{
|
||||||
struct ast_frame *out;
|
struct ast_frame *out;
|
||||||
void *newdata;
|
void *newdata;
|
||||||
@@ -194,7 +197,7 @@ struct ast_frame *ast_frisolate(struct ast_frame *fr)
|
|||||||
since it is more efficient
|
since it is more efficient
|
||||||
*/
|
*/
|
||||||
if (fr->mallocd == 0) {
|
if (fr->mallocd == 0) {
|
||||||
return ast_frdup(fr);
|
return __ast_frdup(fr, file, line, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if everything is already malloc'd, we are done */
|
/* if everything is already malloc'd, we are done */
|
||||||
@@ -205,7 +208,7 @@ struct ast_frame *ast_frisolate(struct ast_frame *fr)
|
|||||||
|
|
||||||
if (!(fr->mallocd & AST_MALLOCD_HDR)) {
|
if (!(fr->mallocd & AST_MALLOCD_HDR)) {
|
||||||
/* Allocate a new header if needed */
|
/* Allocate a new header if needed */
|
||||||
if (!(out = ast_frame_header_new())) {
|
if (!(out = ast_frame_header_new(file, line, func))) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
out->frametype = fr->frametype;
|
out->frametype = fr->frametype;
|
||||||
@@ -291,13 +294,13 @@ struct ast_frame *ast_frisolate(struct ast_frame *fr)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ast_frame *ast_frdup(const struct ast_frame *f)
|
struct ast_frame *__ast_frdup(const struct ast_frame *f, const char *file, int line, const char *func)
|
||||||
{
|
{
|
||||||
struct ast_frame *out = NULL;
|
struct ast_frame *out = NULL;
|
||||||
int len, srclen = 0;
|
int len, srclen = 0;
|
||||||
void *buf = NULL;
|
void *buf = NULL;
|
||||||
|
|
||||||
#if !defined(LOW_MEMORY)
|
#if !defined(NO_FRAME_CACHE)
|
||||||
struct ast_frame_cache *frames;
|
struct ast_frame_cache *frames;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -313,7 +316,7 @@ struct ast_frame *ast_frdup(const struct ast_frame *f)
|
|||||||
if (srclen > 0)
|
if (srclen > 0)
|
||||||
len += srclen + 1;
|
len += srclen + 1;
|
||||||
|
|
||||||
#if !defined(LOW_MEMORY)
|
#if !defined(NO_FRAME_CACHE)
|
||||||
if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames)))) {
|
if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames)))) {
|
||||||
AST_LIST_TRAVERSE_SAFE_BEGIN(&frames->list, out, frame_list) {
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&frames->list, out, frame_list) {
|
||||||
if (out->mallocd_hdr_len >= len) {
|
if (out->mallocd_hdr_len >= len) {
|
||||||
@@ -332,7 +335,7 @@ struct ast_frame *ast_frdup(const struct ast_frame *f)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
if (!(buf = ast_calloc_cache(1, len)))
|
if (!(buf = __ast_calloc(1, len, file, line, func)))
|
||||||
return NULL;
|
return NULL;
|
||||||
out = buf;
|
out = buf;
|
||||||
out->mallocd_hdr_len = len;
|
out->mallocd_hdr_len = len;
|
||||||
|
Reference in New Issue
Block a user