mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-03 19:16:46 +00:00
utils.h: Minor formatting tweaks.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396849 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -484,23 +484,26 @@ static void ast_free_ptr(void *ptr)
|
|||||||
|
|
||||||
#ifndef __AST_DEBUG_MALLOC
|
#ifndef __AST_DEBUG_MALLOC
|
||||||
|
|
||||||
/* This buffer is in static memory. We never intend to read it,
|
/*
|
||||||
|
* This buffer is in static memory. We never intend to read it,
|
||||||
* nor do we care about multiple threads writing to it at the
|
* nor do we care about multiple threads writing to it at the
|
||||||
* same time. We only want to know if we're recursing too deep
|
* same time. We only want to know if we're recursing too deep
|
||||||
* already. 60 entries should be more than enough. Function call
|
* already. 60 entries should be more than enough. Function
|
||||||
* depth rarely exceeds 20 or so. */
|
* call depth rarely exceeds 20 or so.
|
||||||
|
*/
|
||||||
#define _AST_MEM_BACKTRACE_BUFLEN 60
|
#define _AST_MEM_BACKTRACE_BUFLEN 60
|
||||||
extern void *_ast_mem_backtrace_buffer[_AST_MEM_BACKTRACE_BUFLEN];
|
extern void *_ast_mem_backtrace_buffer[_AST_MEM_BACKTRACE_BUFLEN];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ok, this sucks. But if we're already out of mem, we don't
|
||||||
|
* want the logger to create infinite recursion (and a crash).
|
||||||
|
*/
|
||||||
#define MALLOC_FAILURE_MSG \
|
#define MALLOC_FAILURE_MSG \
|
||||||
{ \
|
do { \
|
||||||
/* Ok, this sucks. But if we're already out of mem, we don't \
|
if (backtrace(_ast_mem_backtrace_buffer, _AST_MEM_BACKTRACE_BUFLEN) < _AST_MEM_BACKTRACE_BUFLEN) { \
|
||||||
* want the logger to create infinite recursion (and a crash). */ \
|
|
||||||
if (backtrace(_ast_mem_backtrace_buffer, _AST_MEM_BACKTRACE_BUFLEN) < \
|
|
||||||
_AST_MEM_BACKTRACE_BUFLEN) { \
|
|
||||||
ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file); \
|
ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file); \
|
||||||
} \
|
} \
|
||||||
}
|
} while (0)
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief A wrapper for malloc()
|
* \brief A wrapper for malloc()
|
||||||
@@ -518,8 +521,9 @@ void * attribute_malloc _ast_malloc(size_t len, const char *file, int lineno, co
|
|||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
if (!(p = malloc(len)))
|
if (!(p = malloc(len))) {
|
||||||
MALLOC_FAILURE_MSG;
|
MALLOC_FAILURE_MSG;
|
||||||
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@@ -541,8 +545,9 @@ void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, in
|
|||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
if (!(p = calloc(num, len)))
|
if (!(p = calloc(num, len))) {
|
||||||
MALLOC_FAILURE_MSG;
|
MALLOC_FAILURE_MSG;
|
||||||
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@@ -577,8 +582,9 @@ void * attribute_malloc _ast_realloc(void *p, size_t len, const char *file, int
|
|||||||
{
|
{
|
||||||
void *newp;
|
void *newp;
|
||||||
|
|
||||||
if (!(newp = realloc(p, len)))
|
if (!(newp = realloc(p, len))) {
|
||||||
MALLOC_FAILURE_MSG;
|
MALLOC_FAILURE_MSG;
|
||||||
|
}
|
||||||
|
|
||||||
return newp;
|
return newp;
|
||||||
}
|
}
|
||||||
@@ -605,8 +611,9 @@ char * attribute_malloc _ast_strdup(const char *str, const char *file, int linen
|
|||||||
char *newstr = NULL;
|
char *newstr = NULL;
|
||||||
|
|
||||||
if (str) {
|
if (str) {
|
||||||
if (!(newstr = strdup(str)))
|
if (!(newstr = strdup(str))) {
|
||||||
MALLOC_FAILURE_MSG;
|
MALLOC_FAILURE_MSG;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newstr;
|
return newstr;
|
||||||
@@ -634,8 +641,9 @@ char * attribute_malloc _ast_strndup(const char *str, size_t len, const char *fi
|
|||||||
char *newstr = NULL;
|
char *newstr = NULL;
|
||||||
|
|
||||||
if (str) {
|
if (str) {
|
||||||
if (!(newstr = strndup(str, len)))
|
if (!(newstr = strndup(str, len))) {
|
||||||
MALLOC_FAILURE_MSG;
|
MALLOC_FAILURE_MSG;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newstr;
|
return newstr;
|
||||||
@@ -673,8 +681,9 @@ int _ast_vasprintf(char **ret, const char *file, int lineno, const char *func, c
|
|||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if ((res = vasprintf(ret, fmt, ap)) == -1)
|
if ((res = vasprintf(ret, fmt, ap)) == -1) {
|
||||||
MALLOC_FAILURE_MSG;
|
MALLOC_FAILURE_MSG;
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user