mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
Revamp memory stuff.
Now, if you define ISC_MEM_TRACKLINES, and set isc_mem_debugging = 2 first thing in main(), isc_mem_stats() will dump the file/line where any leaking allocations were made.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: mem.h,v 1.37 2000/06/28 03:46:37 tale Exp $ */
|
||||
/* $Id: mem.h,v 1.38 2000/07/26 19:06:20 explorer Exp $ */
|
||||
|
||||
#ifndef ISC_MEM_H
|
||||
#define ISC_MEM_H 1
|
||||
@@ -37,28 +37,82 @@ typedef void (*isc_memfree_t)(void *, void *);
|
||||
#if !defined(ISC_MEM_DEBUG) && !defined(ISC_MEM_DEBUGOFF)
|
||||
#define ISC_MEM_DEBUG
|
||||
#endif
|
||||
extern isc_boolean_t isc_mem_debugging;
|
||||
|
||||
/*
|
||||
* Define ISC_MEM_TRACKLINES to turn on detailed tracing of memory allocation
|
||||
* and freeing by file and line number.
|
||||
*/
|
||||
#if 0
|
||||
#define ISC_MEM_TRACKLINES
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Define ISC_MEM_CHECKOVERRUN to turn on checks for using memory outside
|
||||
* the requested space. This will increase the size of each allocation.
|
||||
*/
|
||||
#if 0
|
||||
#define ISC_MEM_CHECKOVERRUN
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Define ISC_MEM_FILL to fill each block of memory returned to the system
|
||||
* with the byte string '0xbe'. This helps track down uninitialized pointers
|
||||
* and the like. On freeing memory, the space is filled with '0xde' for
|
||||
* the same reasons.
|
||||
*/
|
||||
#define ISC_MEM_FILL
|
||||
|
||||
/*
|
||||
* Define this to turn on memory pool names.
|
||||
*/
|
||||
#define ISC_MEMPOOL_NAMES
|
||||
|
||||
/*
|
||||
* _DEBUGTRACE
|
||||
* log (to isc_lctx) each allocation and free.
|
||||
*
|
||||
* _DEBUGRECORD
|
||||
* remember each allocation, and match them up on free. Crash if
|
||||
* a free doesn't match an allocation
|
||||
*/
|
||||
extern unsigned int isc_mem_debugging;
|
||||
#define ISC_MEM_DEBUGTRACE 0x00000001U
|
||||
#define ISC_MEM_DEBUGRECORD 0x00000002U
|
||||
|
||||
#ifdef ISC_MEM_TRACKLINES
|
||||
#define _ISC_MEM_FILELINE , __FILE__, __LINE__
|
||||
#define _ISC_MEM_FLARG , const char *, int
|
||||
#else
|
||||
#define _ISC_MEM_FILELINE
|
||||
#define _ISC_MEM_FLARG
|
||||
#endif
|
||||
|
||||
#define isc_mem_get(c, s) isc__mem_get((c), (s) _ISC_MEM_FILELINE)
|
||||
#define isc_mem_allocate(c, s) isc__mem_allocate((c), (s) _ISC_MEM_FILELINE)
|
||||
#define isc_mem_strdup(c, p) isc__mem_strdup((c), (p) _ISC_MEM_FILELINE)
|
||||
#define isc_mempool_get(c) isc__mempool_get((c) _ISC_MEM_FILELINE)
|
||||
|
||||
#ifdef ISC_MEM_DEBUG
|
||||
#define isc_mem_get(c, s) isc__mem_getdebug(c, s, __FILE__, __LINE__)
|
||||
#define isc_mem_put(c, p, s) isc__mem_putdebug(c, p, s, __FILE__, __LINE__)
|
||||
#define isc_mem_allocate(c, s) isc__mem_allocatedebug(c, s, \
|
||||
__FILE__, __LINE__)
|
||||
#define isc_mem_free(c, p) isc__mem_freedebug(c, p, __FILE__, __LINE__)
|
||||
#define isc_mem_strdup(c, p) isc__mem_strdupdebug(c, p, \
|
||||
__FILE__, __LINE__)
|
||||
#define isc_mempool_get(c) isc__mempool_getdebug(c, __FILE__, __LINE__)
|
||||
#define isc_mempool_put(c, p) isc__mempool_putdebug(c, p, \
|
||||
__FILE__, __LINE__)
|
||||
#define isc_mem_put(c, p, s) \
|
||||
do { \
|
||||
isc__mem_put((c), (p), (s) _ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mem_free(c, p) \
|
||||
do { \
|
||||
isc__mem_free((c), (p) _ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mempool_put(c, p) \
|
||||
do { \
|
||||
isc__mempool_put((c), (p) _ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#else
|
||||
#define isc_mem_get isc__mem_get
|
||||
#define isc_mem_put isc__mem_put
|
||||
#define isc_mem_allocate isc__mem_allocate
|
||||
#define isc_mem_free isc__mem_free
|
||||
#define isc_mem_strdup isc__mem_strdup
|
||||
#define isc_mempool_get isc__mempool_get
|
||||
#define isc_mempool_put isc__mempool_put
|
||||
#endif /* ISC_MEM_DEBUG */
|
||||
#define isc_mem_put(c, p, s) isc__mem_put((c), (p), (s) _ISC_MEM_FILELINE)
|
||||
#define isc_mem_free(c, p) isc__mem_free((c), (p) _ISC_MEM_FILELINE)
|
||||
#define isc_mempool_put(c, p) isc__mempool_put((c), (p) _ISC_MEM_FILELINE)
|
||||
#endif
|
||||
|
||||
isc_result_t isc_mem_create(size_t, size_t, isc_mem_t **);
|
||||
void isc_mem_attach(isc_mem_t *, isc_mem_t **);
|
||||
@@ -67,25 +121,19 @@ void isc_mem_destroy(isc_mem_t **);
|
||||
isc_result_t isc_mem_ondestroy(isc_mem_t *ctx,
|
||||
isc_task_t *task,
|
||||
isc_event_t **event);
|
||||
void * isc__mem_get(isc_mem_t *, size_t);
|
||||
void isc__mem_put(isc_mem_t *, void *, size_t);
|
||||
void * isc__mem_getdebug(isc_mem_t *, size_t,
|
||||
const char *, int);
|
||||
void isc__mem_putdebug(isc_mem_t *, void *,
|
||||
size_t, const char *, int);
|
||||
void * isc__mem_get(isc_mem_t *, size_t
|
||||
_ISC_MEM_FLARG);
|
||||
void isc__mem_put(isc_mem_t *, void *,
|
||||
size_t _ISC_MEM_FLARG);
|
||||
isc_result_t isc_mem_preallocate(isc_mem_t *);
|
||||
void isc_mem_stats(isc_mem_t *, FILE *);
|
||||
isc_boolean_t isc_mem_valid(isc_mem_t *, void *);
|
||||
void * isc__mem_allocate(isc_mem_t *, size_t);
|
||||
void * isc__mem_allocatedebug(isc_mem_t *, size_t,
|
||||
const char *, int);
|
||||
void isc__mem_free(isc_mem_t *, void *);
|
||||
void isc__mem_freedebug(isc_mem_t *, void *,
|
||||
const char *, int);
|
||||
char * isc__mem_strdup(isc_mem_t *, const char *);
|
||||
char * isc__mem_strdupdebug(isc_mem_t *,
|
||||
const char *,
|
||||
const char *, int);
|
||||
void * isc__mem_allocate(isc_mem_t *, size_t
|
||||
_ISC_MEM_FLARG);
|
||||
void isc__mem_free(isc_mem_t *, void *
|
||||
_ISC_MEM_FLARG);
|
||||
char * isc__mem_strdup(isc_mem_t *, const char *
|
||||
_ISC_MEM_FLARG);
|
||||
void isc_mem_setdestroycheck(isc_mem_t *,
|
||||
isc_boolean_t);
|
||||
void isc_mem_setsplit(isc_mem_t *, isc_boolean_t);
|
||||
@@ -99,38 +147,6 @@ isc_result_t isc_mem_createx(size_t, size_t,
|
||||
void *arg, isc_mem_t **);
|
||||
isc_result_t isc_mem_restore(isc_mem_t *);
|
||||
|
||||
#ifdef ISC_MEMCLUSTER_LEGACY
|
||||
|
||||
/*
|
||||
* Legacy.
|
||||
*/
|
||||
|
||||
#define meminit isc__legacy_meminit
|
||||
#define mem_default_context isc__legacy_mem_default_context
|
||||
#ifdef MEMCLUSTER_DEBUG
|
||||
#define memget(s) isc__legacy_memget_debug(s, __FILE__, __LINE__)
|
||||
#define memput(p, s) isc__legacy_memput_debug(p, s, \
|
||||
__FILE__, __LINE__)
|
||||
#else
|
||||
#define memget isc__legacy_memget
|
||||
#define memput isc__legacy_memput
|
||||
#endif
|
||||
#define memvalid isc__legacy_memvalid
|
||||
#define memstats isc__legacy_memstats
|
||||
|
||||
int meminit(size_t, size_t);
|
||||
isc_mem_t * mem_default_context(void);
|
||||
void * isc__legacy_memget(size_t);
|
||||
void isc__legacy_memput(void *, size_t);
|
||||
void * isc__legacy_memget_debug(size_t, const char *,
|
||||
int);
|
||||
void isc__legacy_memput_debug(void *, size_t,
|
||||
const char *, int);
|
||||
int memvalid(void *);
|
||||
void memstats(FILE *);
|
||||
|
||||
#endif /* ISC_MEMCLUSTER_LEGACY */
|
||||
|
||||
/*
|
||||
* Memory pools
|
||||
*/
|
||||
@@ -139,11 +155,8 @@ void memstats(FILE *);
|
||||
* Internal (but public) functions. Don't call these from application
|
||||
* code. Use isc_mempool_get() and isc_mempool_put() instead.
|
||||
*/
|
||||
void * isc__mempool_get(isc_mempool_t *);
|
||||
void isc__mempool_put(isc_mempool_t *, void *);
|
||||
void * isc__mempool_getdebug(isc_mempool_t *, const char *, int);
|
||||
void isc__mempool_putdebug(isc_mempool_t *, void *,
|
||||
const char *, int);
|
||||
void * isc__mempool_get(isc_mempool_t * _ISC_MEM_FLARG);
|
||||
void isc__mempool_put(isc_mempool_t *, void * _ISC_MEM_FLARG);
|
||||
|
||||
isc_result_t
|
||||
isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp);
|
||||
|
Reference in New Issue
Block a user