Asterisk - The Open Source Telephony Project  18.5.0
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.

Referenced by __ast_repl_asprintf(), __ast_repl_calloc(), __ast_repl_calloc_cache(), __ast_repl_malloc(), __ast_repl_realloc(), __ast_repl_strdup(), __ast_repl_strndup(), and __ast_repl_vasprintf().

◆ 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)

Function Documentation

◆ __ast_asprintf()

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

Definition at line 1712 of file astmm.c.

References __ast_repl_vasprintf(), MALLOC_FAILURE_MSG, and NULL.

1713 {
1714  int res;
1715  va_list ap;
1716 
1717  va_start(ap, format);
1718  res = __ast_repl_vasprintf(strp, format, ap, file, lineno, func);
1719  if (res < 0) {
1720  /*
1721  * *strp is undefined so set to NULL to ensure it is
1722  * initialized to something useful.
1723  */
1724  *strp = NULL;
1725 
1727  }
1728  va_end(ap);
1729 
1730  return res;
1731 }
#define NULL
Definition: resample.c:96
int __ast_repl_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
Definition: astmm.c:1626
static snd_pcm_format_t format
Definition: chan_alsa.c:102
#define MALLOC_FAILURE_MSG
Definition: astmm.c:70

◆ __ast_calloc()

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

Definition at line 1635 of file astmm.c.

References __ast_repl_calloc(), 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().

1636 {
1637  void *p;
1638 
1639  p = __ast_repl_calloc(nmemb, size, file, lineno, func);
1640  if (!p) {
1642  }
1643 
1644  return p;
1645 }
void * __ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
Definition: astmm.c:1565
#define MALLOC_FAILURE_MSG
Definition: astmm.c:70

◆ __ast_calloc_cache()

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

Definition at line 1647 of file astmm.c.

References __ast_repl_calloc_cache(), and MALLOC_FAILURE_MSG.

1648 {
1649  void *p;
1650 
1651  p = __ast_repl_calloc_cache(nmemb, size, file, lineno, func);
1652  if (!p) {
1654  }
1655 
1656  return p;
1657 
1658 }
static void * __ast_repl_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
Definition: astmm.c:1572
#define MALLOC_FAILURE_MSG
Definition: astmm.c:70

◆ __ast_free()

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

Definition at line 1586 of file astmm.c.

References free().

1587 {
1588  free(ptr);
1589 }
void free()

◆ __ast_malloc()

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

Definition at line 1660 of file astmm.c.

References __ast_repl_malloc(), and MALLOC_FAILURE_MSG.

Referenced by __ast_cc_config_params_init(), and _ast_heap_create().

1661 {
1662  void *p;
1663 
1664  p = __ast_repl_malloc(size, file, lineno, func);
1665  if (!p) {
1667  }
1668 
1669  return p;
1670 }
void * __ast_repl_malloc(size_t size, const char *file, int lineno, const char *func)
Definition: astmm.c:1579
#define MALLOC_FAILURE_MSG
Definition: astmm.c:70

◆ __ast_realloc()

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

Definition at line 1672 of file astmm.c.

References __ast_repl_realloc(), and MALLOC_FAILURE_MSG.

Referenced by grow_heap().

1673 {
1674  void *newp;
1675 
1676  newp = __ast_repl_realloc(ptr, size, file, lineno, func);
1677  if (!newp) {
1679  }
1680 
1681  return newp;
1682 }
void * __ast_repl_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)
Definition: astmm.c:1591
#define MALLOC_FAILURE_MSG
Definition: astmm.c:70

◆ __ast_repl_asprintf()

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

Definition at line 1612 of file astmm.c.

References DEBUG_CHAOS_RETURN, and vasprintf().

1613 {
1614  int res;
1615  va_list ap;
1616 
1617  DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);
1618 
1619  va_start(ap, format);
1620  res = vasprintf(strp, format, ap);
1621  va_end(ap);
1622 
1623  return res;
1624 }
int vasprintf(char **strp, const char *fmt, va_list ap)
#define DEBUG_CHAOS_RETURN(c, f)
DEBUG_CHAOS returns failure randomly.
Definition: astmm.c:59
static snd_pcm_format_t format
Definition: chan_alsa.c:102

◆ __ast_repl_calloc()

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

Definition at line 1565 of file astmm.c.

References calloc, DEBUG_CHAOS_RETURN, and NULL.

Referenced by __ast_calloc().

1566 {
1567  DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
1568 
1569  return calloc(nmemb, size);
1570 }
#define NULL
Definition: resample.c:96
#define calloc(a, b)
Definition: astmm.h:157
#define DEBUG_CHAOS_RETURN(c, f)
DEBUG_CHAOS returns failure randomly.
Definition: astmm.c:59

◆ __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 1572 of file astmm.c.

References calloc, DEBUG_CHAOS_RETURN, and NULL.

Referenced by __ast_calloc_cache().

1573 {
1574  DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
1575 
1576  return calloc(nmemb, size);
1577 }
#define NULL
Definition: resample.c:96
#define calloc(a, b)
Definition: astmm.h:157
#define DEBUG_CHAOS_RETURN(c, f)
DEBUG_CHAOS returns failure randomly.
Definition: astmm.c:59

◆ __ast_repl_malloc()

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

Definition at line 1579 of file astmm.c.

References DEBUG_CHAOS_RETURN, malloc(), and NULL.

Referenced by __ast_malloc().

1580 {
1581  DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
1582 
1583  return malloc(size);
1584 }
#define NULL
Definition: resample.c:96
#define DEBUG_CHAOS_RETURN(c, f)
DEBUG_CHAOS returns failure randomly.
Definition: astmm.c:59
char * malloc()

◆ __ast_repl_realloc()

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

Definition at line 1591 of file astmm.c.

References DEBUG_CHAOS_RETURN, NULL, and realloc.

Referenced by __ast_realloc().

1592 {
1593  DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
1594 
1595  return realloc(ptr, size);
1596 }
#define realloc(a, b)
Definition: astmm.h:163
#define NULL
Definition: resample.c:96
#define DEBUG_CHAOS_RETURN(c, f)
DEBUG_CHAOS returns failure randomly.
Definition: astmm.c:59

◆ __ast_repl_strdup()

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

Definition at line 1598 of file astmm.c.

References DEBUG_CHAOS_RETURN, NULL, and strdup.

Referenced by __ast_strdup().

1599 {
1600  DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
1601 
1602  return strdup(s);
1603 }
#define NULL
Definition: resample.c:96
#define DEBUG_CHAOS_RETURN(c, f)
DEBUG_CHAOS returns failure randomly.
Definition: astmm.c:59
#define strdup(a)
Definition: astmm.h:165

◆ __ast_repl_strndup()

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

Definition at line 1605 of file astmm.c.

References DEBUG_CHAOS_RETURN, NULL, and strndup().

Referenced by __ast_strndup().

1606 {
1607  DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
1608 
1609  return strndup(s, n);
1610 }
char * strndup(const char *, size_t)
#define NULL
Definition: resample.c:96
#define DEBUG_CHAOS_RETURN(c, f)
DEBUG_CHAOS returns failure randomly.
Definition: astmm.c:59

◆ __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 1626 of file astmm.c.

References DEBUG_CHAOS_RETURN, and vasprintf().

Referenced by __ast_asprintf(), and __ast_vasprintf().

1627 {
1628  DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);
1629 
1630  return vasprintf(strp, format, ap);
1631 }
int vasprintf(char **strp, const char *fmt, va_list ap)
#define DEBUG_CHAOS_RETURN(c, f)
DEBUG_CHAOS returns failure randomly.
Definition: astmm.c:59
static snd_pcm_format_t format
Definition: chan_alsa.c:102

◆ __ast_strdup()

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

Definition at line 1684 of file astmm.c.

References __ast_repl_strdup(), MALLOC_FAILURE_MSG, and NULL.

1685 {
1686  char *newstr = NULL;
1687 
1688  if (s) {
1689  newstr = __ast_repl_strdup(s, file, lineno, func);
1690  if (!newstr) {
1692  }
1693  }
1694 
1695  return newstr;
1696 }
char * __ast_repl_strdup(const char *s, const char *file, int lineno, const char *func)
Definition: astmm.c:1598
#define NULL
Definition: resample.c:96
#define MALLOC_FAILURE_MSG
Definition: astmm.c:70

◆ __ast_strndup()

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

Definition at line 1698 of file astmm.c.

References __ast_repl_strndup(), MALLOC_FAILURE_MSG, and NULL.

1699 {
1700  char *newstr = NULL;
1701 
1702  if (s) {
1703  newstr = __ast_repl_strndup(s, n, file, lineno, func);
1704  if (!newstr) {
1706  }
1707  }
1708 
1709  return newstr;
1710 }
char * __ast_repl_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)
Definition: astmm.c:1605
#define NULL
Definition: resample.c:96
#define MALLOC_FAILURE_MSG
Definition: astmm.c:70

◆ __ast_vasprintf()

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

Definition at line 1733 of file astmm.c.

References __ast_repl_vasprintf(), MALLOC_FAILURE_MSG, and NULL.

1734 {
1735  int res;
1736 
1737  res = __ast_repl_vasprintf(strp, format, ap, file, lineno, func);
1738  if (res < 0) {
1739  /*
1740  * *strp is undefined so set to NULL to ensure it is
1741  * initialized to something useful.
1742  */
1743  *strp = NULL;
1744 
1746  }
1747 
1748  return res;
1749 }
#define NULL
Definition: resample.c:96
int __ast_repl_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
Definition: astmm.c:1626
static snd_pcm_format_t format
Definition: chan_alsa.c:102
#define MALLOC_FAILURE_MSG
Definition: astmm.c:70

◆ 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 1756 of file astmm.c.

References calloc.

Referenced by ast_get_reentrancy(), and ast_module_register().

1757 {
1758  return calloc(nmemb, size);
1759 }
#define calloc(a, b)
Definition: astmm.h:157

◆ ast_std_free()

void ast_std_free ( void *  ptr)

◆ ast_std_malloc()

void* ast_std_malloc ( size_t  size)

Definition at line 1751 of file astmm.c.

References malloc().

1752 {
1753  return malloc(size);
1754 }
char * malloc()

◆ ast_std_realloc()

void* ast_std_realloc ( void *  ptr,
size_t  size 
)

Definition at line 1761 of file astmm.c.

References realloc.

1762 {
1763  return realloc(ptr, size);
1764 }
#define realloc(a, b)
Definition: astmm.h:163

◆ load_astmm_phase_1()

void load_astmm_phase_1 ( void  )

Initialize malloc debug phase 1.

Note
Must be called first thing after forking.
Returns
Nothing

Definition at line 1557 of file astmm.c.

Referenced by asterisk_daemon().

1558 {
1559 }

◆ load_astmm_phase_2()

void load_astmm_phase_2 ( void  )

Initialize malloc debug phase 2.

Returns
Nothing

Definition at line 1561 of file astmm.c.

Referenced by asterisk_daemon().

1562 {
1563 }