|
ELinks 0.19.1
|
Memory debugging (leaks, overflows & co). More...
#include <signal.h>#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "elinks.h"#include "util/error.h"#include "util/lists.h"#include "util/memdebug.h"#include "util/memory.h"
Data Structures | |
| struct | alloc_header |
Macros | |
| #define | LESS_MEMORY_SPEED |
| Eat less memory, but sacrifice speed? | |
| #define | FILL_ON_ALLOC |
| Fill memory on alloc() ? | |
| #define | FILL_ON_ALLOC_VALUE 'X' |
| #define | FILL_ON_REALLOC |
| Fill memory on realloc() ? | |
| #define | FILL_ON_REALLOC_VALUE 'Y' |
| #define | FILL_ON_FREE_VALUE 'Z' |
| Fill memory before free() ? | |
| #define | CHECK_AH_SANITY |
| Check alloc_header block sanity ? | |
| #define | AH_SANITY_MAGIC 0xD3BA110C |
| #define | CHECK_DOUBLE_FREE |
| Check for useless reallocation ? | |
| #define | AH_FREE_MAGIC 0xD3BF110C |
| #define | CHECK_XFLOWS |
| Check for overflows and underflows ? | |
| #define | XFLOW_MAGIC (char) 0xFA |
| #define | SIZE_AH_ALIGNED ((sizeof(struct alloc_header) + 7) & ~7) |
| #define | XFLOW_INC 1 |
| #define | PTR_AH2BASE(ah) |
| #define | PTR_BASE2AH(ptr) |
| #define | SIZE_BASE2AH(size) |
| #define | SIZE_AH2BASE(size) |
| #define | PTR_OVERFLOW_MAGIC(ah) |
| #define | PTR_UNDERFLOW_MAGIC(ah) |
| #define | SET_OVERFLOW_MAGIC(ah) |
| #define | SET_UNDERFLOW_MAGIC(ah) |
| #define | SET_XFLOW_MAGIC(ah) |
| #define | dump_short_info(a, b, c, d) |
Functions | |
| static void | dump_info (struct alloc_header *ah, const char *info, const char *file, int line, const char *type) |
| static int | bad_ah_sanity (struct alloc_header *ah, const char *info, const char *file, int line) |
| static int | bad_xflow_magic (struct alloc_header *ah, const char *info, const char *file, int line) |
| void | check_memory_leaks (void) |
| static int | patience (const char *file, int line, const char *of) |
| void * | debug_mem_alloc (const char *file, int line, size_t size) |
| void * | debug_mem_calloc (const char *file, int line, size_t eltcount, size_t eltsize) |
| void | debug_mem_free (const char *file, int line, void *ptr) |
| void * | debug_mem_realloc (const char *file, int line, void *ptr, size_t size) |
| void | set_mem_comment (void *ptr, const char *str, int len) |
Variables | |
| struct mem_stats | mem_stats |
| struct alloc_header list | memory_list = { D_LIST_HEAD_EL(memory_list) } |
| static int | alloc_try = 0 |
Memory debugging (leaks, overflows & co).
Wrappers for libc memory managment providing protection against common pointers manipulation mistakes - bad realloc()/free() pointers, double free() problem, using uninitialized/freed memory, underflow/overflow protection, leaks tracking...
Copyright (C) 1999 - 2002 Mikulas Patocka Copyright (C) 2001 - 2004 Petr Baudis Copyright (C) 2002 - 2003 Laurent Monin
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA This file is covered by the General Public Licence v2.
| #define AH_FREE_MAGIC 0xD3BF110C |
| #define AH_SANITY_MAGIC 0xD3BA110C |
| #define CHECK_AH_SANITY |
Check alloc_header block sanity ?
Default is defined.
| #define CHECK_DOUBLE_FREE |
Check for useless reallocation ?
If oldsize is equal to newsize, print a message to stderr. It may help to find inefficient code. Default is undefined. Check for validity of address passed to free() ? Note that this is VERY slow, as we iterate through whole memory_list each time. We can't check magics etc, as it would break double free() check. Default is undef. Check for double free ? Default is defined.
| #define CHECK_XFLOWS |
Check for overflows and underflows ?
Default is defined.
| #define dump_short_info | ( | a, | |
| b, | |||
| c, | |||
| d ) |
| #define FILL_ON_ALLOC |
Fill memory on alloc() ?
Default is defined.
| #define FILL_ON_ALLOC_VALUE 'X' |
| #define FILL_ON_FREE_VALUE 'Z' |
Fill memory before free() ?
Default is undef.
| #define FILL_ON_REALLOC |
Fill memory on realloc() ?
Default is defined.
| #define FILL_ON_REALLOC_VALUE 'Y' |
| #define LESS_MEMORY_SPEED |
Eat less memory, but sacrifice speed?
Default is defined.
| #define PTR_AH2BASE | ( | ah | ) |
| #define PTR_BASE2AH | ( | ptr | ) |
| #define PTR_OVERFLOW_MAGIC | ( | ah | ) |
| #define PTR_UNDERFLOW_MAGIC | ( | ah | ) |
| #define SET_OVERFLOW_MAGIC | ( | ah | ) |
| #define SET_UNDERFLOW_MAGIC | ( | ah | ) |
| #define SET_XFLOW_MAGIC | ( | ah | ) |
| #define SIZE_AH2BASE | ( | size | ) |
| #define SIZE_AH_ALIGNED ((sizeof(struct alloc_header) + 7) & ~7) |
| #define SIZE_BASE2AH | ( | size | ) |
| #define XFLOW_INC 1 |
| #define XFLOW_MAGIC (char) 0xFA |
|
inlinestatic |
|
inlinestatic |
| void check_memory_leaks | ( | void | ) |
| void * debug_mem_alloc | ( | const char * | file, |
| int | line, | ||
| size_t | size ) |
| void * debug_mem_calloc | ( | const char * | file, |
| int | line, | ||
| size_t | eltcount, | ||
| size_t | eltsize ) |
| void debug_mem_free | ( | const char * | file, |
| int | line, | ||
| void * | ptr ) |
| void * debug_mem_realloc | ( | const char * | file, |
| int | line, | ||
| void * | ptr, | ||
| size_t | size ) |
|
static |
|
static |
| void set_mem_comment | ( | void * | ptr, |
| const char * | str, | ||
| int | len ) |
|
static |
| struct mem_stats mem_stats |
| struct alloc_header list memory_list = { D_LIST_HEAD_EL(memory_list) } |