Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Macros | Functions
astmm.c File Reference

Memory Management. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/logger.h"
Include dependency graph for astmm.c:

Go to the source code of this file.

Macros

#define ASTMM_LIBC   ASTMM_IGNORE
 
#define DEBUG_CHAOS_RETURN(c, f)
 DEBUG_CHAOS returns failure randomly. More...
 
#define MALLOC_FAILURE_MSG    ast_log_safe(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file)
 

Functions

int __ast_asprintf (const char *file, int lineno, const char *func, char **strp, const char *format,...)
 
void * __ast_calloc (size_t nmemb, size_t size, 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_free (void *ptr, const char *file, int lineno, const char *func)
 
void * __ast_malloc (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)
 
int __ast_repl_asprintf (const char *file, int lineno, const char *func, char **strp, const char *format,...)
 
void * __ast_repl_calloc (size_t nmemb, size_t size, const char *file, int lineno, const char *func)
 
static void * __ast_repl_calloc_cache (size_t nmemb, size_t size, const char *file, int lineno, const char *func)
 
void * __ast_repl_malloc (size_t size, const char *file, int lineno, const char *func)
 
void * __ast_repl_realloc (void *ptr, size_t size, const char *file, int lineno, const char *func)
 
char * __ast_repl_strdup (const char *s, const char *file, int lineno, const char *func)
 
char * __ast_repl_strndup (const char *s, size_t n, const char *file, int lineno, const char *func)
 
int __ast_repl_vasprintf (char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
 
char * __ast_strdup (const char *s, 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)
 
int __ast_vasprintf (char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
 
void ast_free_ptr (void *ptr)
 free() wrapper More...
 
void * ast_std_calloc (size_t nmemb, size_t size)
 
void ast_std_free (void *ptr)
 
void * ast_std_malloc (size_t size)
 
void * ast_std_realloc (void *ptr, size_t size)
 
void load_astmm_phase_1 (void)
 Initialize malloc debug phase 1. More...
 
void load_astmm_phase_2 (void)
 Initialize malloc debug phase 2. More...
 

Detailed Description

Memory Management.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m
Richard Mudgett rmudg.nosp@m.ett@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file astmm.c.

Macro Definition Documentation

◆ ASTMM_LIBC

#define ASTMM_LIBC   ASTMM_IGNORE

Definition at line 31 of file astmm.c.

◆ DEBUG_CHAOS_RETURN

#define DEBUG_CHAOS_RETURN (   c,
 
)

DEBUG_CHAOS returns failure randomly.

DEBUG_CHAOS_RETURN(failure); can be used to fake failure of functions such as memory allocation, for the purposes of testing failure handling.

Definition at line 59 of file astmm.c.

◆ MALLOC_FAILURE_MSG

#define MALLOC_FAILURE_MSG    ast_log_safe(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file)

Definition at line 70 of file astmm.c.

Function Documentation

◆ __ast_asprintf()

int __ast_asprintf ( const char *  file,
int  lineno,
const char *  func,
char **  strp,
const char *  format,
  ... 
)

Definition at line 1680 of file astmm.c.

1681{
1682 int res;
1683 va_list ap;
1684
1685 va_start(ap, format);
1686 res = __ast_repl_vasprintf(strp, format, ap, file, lineno, func);
1687 if (res < 0) {
1688 /*
1689 * *strp is undefined so set to NULL to ensure it is
1690 * initialized to something useful.
1691 */
1692 *strp = NULL;
1693
1695 }
1696 va_end(ap);
1697
1698 return res;
1699}
int __ast_repl_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
Definition: astmm.c:1594
#define MALLOC_FAILURE_MSG
Definition: astmm.c:70
#define NULL
Definition: resample.c:96

References __ast_repl_vasprintf(), make_ari_stubs::file, MALLOC_FAILURE_MSG, and NULL.

◆ __ast_calloc()

void * __ast_calloc ( size_t  nmemb,
size_t  size,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1603 of file astmm.c.

1604{
1605 void *p;
1606
1607 p = __ast_repl_calloc(nmemb, size, file, lineno, func);
1608 if (!p) {
1610 }
1611
1612 return p;
1613}
void * __ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
Definition: astmm.c:1533

References __ast_repl_calloc(), make_ari_stubs::file, and MALLOC_FAILURE_MSG.

Referenced by __ast_calloc_with_stringfields(), __ast_datastore_alloc(), __ast_frdup(), _ast_hashtab_create(), _ast_hashtab_dup(), _ast_hashtab_insert_immediate_bucket(), _ast_hashtab_resize(), _ast_hashtab_start_traversal(), _ast_hashtab_start_write_traversal(), _ast_heap_create(), _ast_var_assign(), _ast_variable_new(), add_string_pool(), ast_frame_header_new(), and internal_ao2_alloc().

◆ __ast_calloc_cache()

void * __ast_calloc_cache ( size_t  nmemb,
size_t  size,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1615 of file astmm.c.

1616{
1617 void *p;
1618
1619 p = __ast_repl_calloc_cache(nmemb, size, file, lineno, func);
1620 if (!p) {
1622 }
1623
1624 return p;
1625
1626}
static void * __ast_repl_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
Definition: astmm.c:1540

References __ast_repl_calloc_cache(), make_ari_stubs::file, and MALLOC_FAILURE_MSG.

◆ __ast_free()

void __ast_free ( void *  ptr,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1554 of file astmm.c.

1555{
1556 free(ptr);
1557}
void free()

References free().

◆ __ast_malloc()

void * __ast_malloc ( size_t  size,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1628 of file astmm.c.

1629{
1630 void *p;
1631
1632 p = __ast_repl_malloc(size, file, lineno, func);
1633 if (!p) {
1635 }
1636
1637 return p;
1638}
void * __ast_repl_malloc(size_t size, const char *file, int lineno, const char *func)
Definition: astmm.c:1547

References __ast_repl_malloc(), make_ari_stubs::file, and MALLOC_FAILURE_MSG.

Referenced by __ast_cc_config_params_init(), and _ast_heap_create().

◆ __ast_realloc()

void * __ast_realloc ( void *  ptr,
size_t  size,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1640 of file astmm.c.

1641{
1642 void *newp;
1643
1644 newp = __ast_repl_realloc(ptr, size, file, lineno, func);
1645 if (!newp) {
1647 }
1648
1649 return newp;
1650}
void * __ast_repl_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)
Definition: astmm.c:1559

References __ast_repl_realloc(), make_ari_stubs::file, and MALLOC_FAILURE_MSG.

Referenced by grow_heap().

◆ __ast_repl_asprintf()

int __ast_repl_asprintf ( const char *  file,
int  lineno,
const char *  func,
char **  strp,
const char *  format,
  ... 
)

Definition at line 1580 of file astmm.c.

1581{
1582 int res;
1583 va_list ap;
1584
1585 DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);
1586
1587 va_start(ap, format);
1588 res = vasprintf(strp, format, ap);
1589 va_end(ap);
1590
1591 return res;
1592}
#define DEBUG_CHAOS_RETURN(c, f)
DEBUG_CHAOS returns failure randomly.
Definition: astmm.c:59
int vasprintf(char **strp, const char *fmt, va_list ap)

References DEBUG_CHAOS_RETURN, and vasprintf().

◆ __ast_repl_calloc()

void * __ast_repl_calloc ( size_t  nmemb,
size_t  size,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1533 of file astmm.c.

1534{
1535 DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
1536
1537 return calloc(nmemb, size);
1538}
#define calloc(a, b)
Definition: astmm.h:155

References calloc, DEBUG_CHAOS_RETURN, and NULL.

Referenced by __ast_calloc().

◆ __ast_repl_calloc_cache()

static void * __ast_repl_calloc_cache ( size_t  nmemb,
size_t  size,
const char *  file,
int  lineno,
const char *  func 
)
static

Definition at line 1540 of file astmm.c.

1541{
1542 DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
1543
1544 return calloc(nmemb, size);
1545}

References calloc, DEBUG_CHAOS_RETURN, and NULL.

Referenced by __ast_calloc_cache().

◆ __ast_repl_malloc()

void * __ast_repl_malloc ( size_t  size,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1547 of file astmm.c.

1548{
1549 DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
1550
1551 return malloc(size);
1552}
char * malloc()

References DEBUG_CHAOS_RETURN, malloc(), and NULL.

Referenced by __ast_malloc().

◆ __ast_repl_realloc()

void * __ast_repl_realloc ( void *  ptr,
size_t  size,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1559 of file astmm.c.

1560{
1561 DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
1562
1563 return realloc(ptr, size);
1564}
#define realloc(a, b)
Definition: astmm.h:161

References DEBUG_CHAOS_RETURN, NULL, and realloc.

Referenced by __ast_realloc().

◆ __ast_repl_strdup()

char * __ast_repl_strdup ( const char *  s,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1566 of file astmm.c.

1567{
1568 DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
1569
1570 return strdup(s);
1571}
#define strdup(a)
Definition: astmm.h:163

References DEBUG_CHAOS_RETURN, NULL, and strdup.

Referenced by __ast_strdup().

◆ __ast_repl_strndup()

char * __ast_repl_strndup ( const char *  s,
size_t  n,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1573 of file astmm.c.

1574{
1575 DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
1576
1577 return strndup(s, n);
1578}
char * strndup(const char *, size_t)

References DEBUG_CHAOS_RETURN, NULL, and strndup().

Referenced by __ast_strndup().

◆ __ast_repl_vasprintf()

int __ast_repl_vasprintf ( char **  strp,
const char *  format,
va_list  ap,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1594 of file astmm.c.

1595{
1596 DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);
1597
1598 return vasprintf(strp, format, ap);
1599}

References DEBUG_CHAOS_RETURN, and vasprintf().

Referenced by __ast_asprintf(), and __ast_vasprintf().

◆ __ast_strdup()

char * __ast_strdup ( const char *  s,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1652 of file astmm.c.

1653{
1654 char *newstr = NULL;
1655
1656 if (s) {
1657 newstr = __ast_repl_strdup(s, file, lineno, func);
1658 if (!newstr) {
1660 }
1661 }
1662
1663 return newstr;
1664}
char * __ast_repl_strdup(const char *s, const char *file, int lineno, const char *func)
Definition: astmm.c:1566

References __ast_repl_strdup(), make_ari_stubs::file, MALLOC_FAILURE_MSG, and NULL.

◆ __ast_strndup()

char * __ast_strndup ( const char *  s,
size_t  n,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1666 of file astmm.c.

1667{
1668 char *newstr = NULL;
1669
1670 if (s) {
1671 newstr = __ast_repl_strndup(s, n, file, lineno, func);
1672 if (!newstr) {
1674 }
1675 }
1676
1677 return newstr;
1678}
char * __ast_repl_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)
Definition: astmm.c:1573

References __ast_repl_strndup(), make_ari_stubs::file, MALLOC_FAILURE_MSG, and NULL.

◆ __ast_vasprintf()

int __ast_vasprintf ( char **  strp,
const char *  format,
va_list  ap,
const char *  file,
int  lineno,
const char *  func 
)

Definition at line 1701 of file astmm.c.

1702{
1703 int res;
1704
1705 res = __ast_repl_vasprintf(strp, format, ap, file, lineno, func);
1706 if (res < 0) {
1707 /*
1708 * *strp is undefined so set to NULL to ensure it is
1709 * initialized to something useful.
1710 */
1711 *strp = NULL;
1712
1714 }
1715
1716 return res;
1717}

References __ast_repl_vasprintf(), make_ari_stubs::file, MALLOC_FAILURE_MSG, and NULL.

◆ ast_free_ptr()

void ast_free_ptr ( void *  ptr)

◆ ast_std_calloc()

void * ast_std_calloc ( size_t  nmemb,
size_t  size 
)

Definition at line 1724 of file astmm.c.

1725{
1726 return calloc(nmemb, size);
1727}

References calloc.

Referenced by ast_module_register().

◆ ast_std_free()

void ast_std_free ( void *  ptr)

◆ ast_std_malloc()

void * ast_std_malloc ( size_t  size)

Definition at line 1719 of file astmm.c.

1720{
1721 return malloc(size);
1722}

References malloc().

◆ ast_std_realloc()

void * ast_std_realloc ( void *  ptr,
size_t  size 
)

Definition at line 1729 of file astmm.c.

1730{
1731 return realloc(ptr, size);
1732}

References realloc.

◆ load_astmm_phase_1()

void load_astmm_phase_1 ( void  )

Initialize malloc debug phase 1.

Note
Must be called first thing after forking.

Definition at line 1525 of file astmm.c.

1526{
1527}

Referenced by asterisk_daemon().

◆ load_astmm_phase_2()

void load_astmm_phase_2 ( void  )

Initialize malloc debug phase 2.

Definition at line 1529 of file astmm.c.

1530{
1531}

Referenced by asterisk_daemon().