#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | Malloc_check_vals |
struct | Malloc_check_store |
Defines | |
#define | MALLOC_CHECK_H 1 |
#define | MALLOC_CHECK__ATTR_USED() |
#define | MALLOC_CHECK__ATTR_H() |
#define | MALLOC_CHECK__ATTR_MALLOC() |
#define | MALLOC_CHECK_API_M_SCRUB 0 |
#define | MALLOC_CHECK_API_F_SCRUB 0 |
#define | MALLOC_CHECK_API_R_SCRUB 0 |
#define | MALLOC_CHECK_STORE malloc_check__app_store |
#define | MALLOC_CHECK_REINIT() |
#define | MALLOC_CHECK_INIT() |
#define | USE_MALLOC_CHECK 1 |
#define | MALLOC_CHECK_FUNC_NAME "" |
#define | MALLOC_CHECK_MEM(x) malloc_check_mem(x, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
#define | MALLOC_CHECK_MEM_SZ(x, y) malloc_check_mem_sz(x, y, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
#define | MALLOC_CHECK_MEM_MINSZ(x, y) malloc_check_mem_minsz(x, y, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
#define | MALLOC_CHECK_EMPTY() malloc_check_empty(__FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
#define | MC_MALLOC(x) malloc_check_malloc(x, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
#define | MC_CALLOC(x, y) malloc_check_calloc(x, y, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
#define | MC_REALLOC(x, y) malloc_check_realloc(x, y, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
#define | MC_FREE(x) malloc_check_free(x, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
#define | MALLOC_CHECK_SCOPE_EXTERN 1 |
#define | malloc_check_assert(x) |
#define | MALLOC_CHECK_ASSERT(x) |
#define | MALLOC_CHECK_DECL() Malloc_check_store MALLOC_CHECK_STORE = {0, 0, 0, NULL} |
#define | MALLOC_CHECK_DEC() (MALLOC_CHECK_STORE.mem_fail_num && !--MALLOC_CHECK_STORE.mem_fail_num) |
#define | MALLOC_CHECK_FAIL_IN(x) MALLOC_CHECK_STORE.mem_fail_num = (x) |
#define | MALLOC_CHECK_SCRUB_PTR(x, y) memset(x, 0xa5, y) |
#define | MALLOC_CHECK_PRINT 1 |
#define | MALLOC_CHECK_TRACE 0 |
#define | MALLOC_CHECK_SWAP_TYPE(x, y, type) |
Functions | |
static void | malloc_check_alloc (const char *, unsigned int, const char *) |
static unsigned int | malloc_check_mem (const void *, const char *, unsigned int, const char *) |
static unsigned int | malloc_check_mem_sz (const void *, size_t, const char *, unsigned int, const char *) |
static unsigned int | malloc_check_mem_minsz (const void *, size_t, const char *, unsigned int, const char *) |
static void * | malloc_check_malloc (size_t, const char *, unsigned int, const char *) |
static void * | malloc_check_calloc (size_t, size_t, const char *, unsigned int, const char *) |
static void | malloc_check_free (void *, const char *, unsigned int, const char *) |
static void * | malloc_check_realloc (void *, size_t, const char *, unsigned int, const char *) |
static void | malloc_check_empty (const char *, unsigned int, const char *) |
Variables | |
Malloc_check_store | malloc_check__app_store |
#define MALLOC_CHECK__ATTR_H | ( | ) |
Definition at line 16 of file malloc-check.h.
#define MALLOC_CHECK__ATTR_MALLOC | ( | ) |
Definition at line 24 of file malloc-check.h.
#define MALLOC_CHECK__ATTR_USED | ( | ) |
Definition at line 8 of file malloc-check.h.
#define MALLOC_CHECK_API_F_SCRUB 0 |
#define MALLOC_CHECK_API_M_SCRUB 0 |
#define MALLOC_CHECK_API_R_SCRUB 0 |
#define MALLOC_CHECK_ASSERT | ( | x | ) |
Value:
do { \ if (x) {} else { \ fprintf(stderr, " -=> MC_ASSERT (%s) failed, caller=%s:%s:%d.\n", \ #x , func, file, line); \ abort(); } \ } while (0)
Definition at line 146 of file malloc-check.h.
Referenced by malloc_check_malloc(), and malloc_check_realloc().
#define malloc_check_assert | ( | x | ) |
Value:
do { \ if (x) {} else { \ fprintf(stderr, " -=> mc_assert (%s) failed, caller=%s:%s:%d.\n", \ #x , func, file, line); \ abort(); } \ } while (0)
Definition at line 140 of file malloc-check.h.
Referenced by malloc_check_alloc(), malloc_check_empty(), malloc_check_free(), malloc_check_mem(), malloc_check_mem_minsz(), and malloc_check_mem_sz().
#define MALLOC_CHECK_DEC | ( | ) | (MALLOC_CHECK_STORE.mem_fail_num && !--MALLOC_CHECK_STORE.mem_fail_num) |
Definition at line 161 of file malloc-check.h.
Referenced by malloc_check_malloc(), and malloc_check_realloc().
#define MALLOC_CHECK_DECL | ( | ) | Malloc_check_store MALLOC_CHECK_STORE = {0, 0, 0, NULL} |
Definition at line 154 of file malloc-check.h.
#define MALLOC_CHECK_EMPTY | ( | ) | malloc_check_empty(__FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
Definition at line 76 of file malloc-check.h.
#define MALLOC_CHECK_FAIL_IN | ( | x | ) | MALLOC_CHECK_STORE.mem_fail_num = (x) |
Definition at line 163 of file malloc-check.h.
#define MALLOC_CHECK_FUNC_NAME "" |
Definition at line 66 of file malloc-check.h.
#define MALLOC_CHECK_H 1 |
Definition at line 2 of file malloc-check.h.
#define MALLOC_CHECK_INIT | ( | ) |
Value:
MALLOC_CHECK_STORE.mem_fail_num = 0; \ MALLOC_CHECK_REINIT()
Definition at line 49 of file malloc-check.h.
#define MALLOC_CHECK_MEM | ( | x | ) | malloc_check_mem(x, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
Definition at line 70 of file malloc-check.h.
#define MALLOC_CHECK_MEM_MINSZ | ( | x, | |||
y | ) | malloc_check_mem_minsz(x, y, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
Definition at line 74 of file malloc-check.h.
#define MALLOC_CHECK_MEM_SZ | ( | x, | |||
y | ) | malloc_check_mem_sz(x, y, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
Definition at line 72 of file malloc-check.h.
#define MALLOC_CHECK_PRINT 1 |
#define MALLOC_CHECK_REINIT | ( | ) |
Value:
MALLOC_CHECK_STORE.mem_sz = 0; \ MALLOC_CHECK_STORE.mem_num = 0; \ MALLOC_CHECK_STORE.mem_vals = NULL
Definition at line 45 of file malloc-check.h.
#define MALLOC_CHECK_SCOPE_EXTERN 1 |
Definition at line 130 of file malloc-check.h.
#define MALLOC_CHECK_SCRUB_PTR | ( | x, | |||
y | ) | memset(x, 0xa5, y) |
Definition at line 164 of file malloc-check.h.
Referenced by malloc_check_free(), and malloc_check_malloc().
#define MALLOC_CHECK_STORE malloc_check__app_store |
Definition at line 41 of file malloc-check.h.
#define MALLOC_CHECK_SWAP_TYPE | ( | x, | |||
y, | |||||
type | ) |
Value:
do { \ type internal_local_tmp = (x); \ (x) = (y); \ (y) = internal_local_tmp; \ } while (0)
Definition at line 175 of file malloc-check.h.
Referenced by malloc_check_free().
#define MALLOC_CHECK_TRACE 0 |
Definition at line 171 of file malloc-check.h.
Referenced by malloc_check_free(), malloc_check_malloc(), and malloc_check_realloc().
#define MC_CALLOC | ( | x, | |||
y | ) | malloc_check_calloc(x, y, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
Definition at line 82 of file malloc-check.h.
#define MC_FREE | ( | x | ) | malloc_check_free(x, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
Definition at line 86 of file malloc-check.h.
#define MC_MALLOC | ( | x | ) | malloc_check_malloc(x, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
Definition at line 80 of file malloc-check.h.
#define MC_REALLOC | ( | x, | |||
y | ) | malloc_check_realloc(x, y, __FILE__, __LINE__, MALLOC_CHECK_FUNC_NAME) |
Definition at line 84 of file malloc-check.h.
#define USE_MALLOC_CHECK 1 |
Definition at line 55 of file malloc-check.h.
static void malloc_check_alloc | ( | const char * | file, | |
unsigned int | line, | |||
const char * | func | |||
) | [static] |
Definition at line 203 of file malloc-check.h.
References malloc_check_assert.
Referenced by malloc_check_malloc().
static void * malloc_check_calloc | ( | size_t | num, | |
size_t | sz, | |||
const char * | file, | |||
unsigned int | line, | |||
const char * | func | |||
) | [static] |
static void malloc_check_empty | ( | const char * | file, | |
unsigned int | line, | |||
const char * | func | |||
) | [static] |
Definition at line 395 of file malloc-check.h.
References malloc_check_assert, and MALLOC_CHECK_PRINT.
static void malloc_check_free | ( | void * | ptr, | |
const char * | file, | |||
unsigned int | line, | |||
const char * | func | |||
) | [static] |
Definition at line 313 of file malloc-check.h.
References Malloc_check_vals::file, Malloc_check_vals::func, Malloc_check_vals::line, MALLOC_CHECK_API_F_SCRUB, malloc_check_assert, malloc_check_mem(), MALLOC_CHECK_SCRUB_PTR, MALLOC_CHECK_SWAP_TYPE, MALLOC_CHECK_TRACE, Malloc_check_vals::ptr, and Malloc_check_vals::sz.
Referenced by malloc_check_realloc().
static void * malloc_check_malloc | ( | size_t | sz, | |
const char * | file, | |||
unsigned int | line, | |||
const char * | func | |||
) | [static] |
Definition at line 265 of file malloc-check.h.
References malloc_check_alloc(), MALLOC_CHECK_API_M_SCRUB, MALLOC_CHECK_ASSERT, MALLOC_CHECK_DEC, MALLOC_CHECK_SCRUB_PTR, and MALLOC_CHECK_TRACE.
Referenced by malloc_check_calloc(), and malloc_check_realloc().
static unsigned int malloc_check_mem | ( | const void * | ptr, | |
const char * | file, | |||
unsigned int | line, | |||
const char * | func | |||
) | [static] |
Definition at line 226 of file malloc-check.h.
References malloc_check_assert.
Referenced by malloc_check_free(), malloc_check_mem_minsz(), malloc_check_mem_sz(), and malloc_check_realloc().
static unsigned int malloc_check_mem_minsz | ( | const void * | ptr, | |
size_t | sz, | |||
const char * | file, | |||
unsigned int | line, | |||
const char * | func | |||
) | [static] |
Definition at line 254 of file malloc-check.h.
References malloc_check_assert, and malloc_check_mem().
static unsigned int malloc_check_mem_sz | ( | const void * | ptr, | |
size_t | sz, | |||
const char * | file, | |||
unsigned int | line, | |||
const char * | func | |||
) | [static] |
Definition at line 243 of file malloc-check.h.
References malloc_check_assert, and malloc_check_mem().
static void * malloc_check_realloc | ( | void * | ptr, | |
size_t | sz, | |||
const char * | file, | |||
unsigned int | line, | |||
const char * | func | |||
) | [static] |
Definition at line 349 of file malloc-check.h.
References MALLOC_CHECK_API_R_SCRUB, MALLOC_CHECK_ASSERT, MALLOC_CHECK_DEC, malloc_check_free(), malloc_check_malloc(), malloc_check_mem(), and MALLOC_CHECK_TRACE.