From 0ef59eaa9f7db0ebc00127e43f030f9adddd53ef Mon Sep 17 00:00:00 2001 From: James Brister Date: Sat, 2 Oct 1999 21:20:03 +0000 Subject: [PATCH] Let client turn off the INSIST that all memory is freed (parser needs this due to yacc). --- lib/isc/include/isc/mem.h | 1 + lib/isc/mem.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/isc/include/isc/mem.h b/lib/isc/include/isc/mem.h index 334f94815a..3671d8fb0f 100644 --- a/lib/isc/include/isc/mem.h +++ b/lib/isc/include/isc/mem.h @@ -58,6 +58,7 @@ isc_boolean_t isc_mem_valid(isc_mem_t *, void *); void * isc_mem_allocate(isc_mem_t *, size_t); void isc_mem_free(isc_mem_t *, void *); char * isc_mem_strdup(isc_mem_t *, const char *); +isc_boolean_t isc_mem_destroy_check(isc_mem_t *, isc_boolean_t); void isc_mem_setquota(isc_mem_t *, size_t); size_t isc_mem_getquota(isc_mem_t *); diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 034eab3043..e79989fa1d 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -86,6 +86,7 @@ struct isc_mem { unsigned int basic_table_size; unsigned char * lowest; unsigned char * highest; + isc_boolean_t checkfree; struct stats * stats; size_t quota; size_t total; @@ -191,6 +192,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size, (memfree)(arg, ctx); return (ISC_R_NOMEMORY); } + ctx->checkfree = ISC_TRUE; memset(ctx->freelists, 0, ctx->max_size * sizeof (element *)); ctx->stats = (memalloc)(arg, @@ -246,14 +248,24 @@ isc_mem_destroy(isc_mem_t **ctxp) { INSIST(ISC_LIST_EMPTY(ctx->pools)); - for (i = 0; i <= ctx->max_size; i++) - INSIST(ctx->stats[i].gets == 0); + if (ctx->checkfree) { + for (i = 0; i <= ctx->max_size; i++) + INSIST(ctx->stats[i].gets == 0); + } + +#if 0 /* XXX brister debugging */ + for (i = 0; i < ctx->basic_table_count; i++) + memset(ctx->basic_table[i], 0x0, + NUM_BASIC_BLOCKS * ctx->mem_target); +#endif + for (i = 0; i < ctx->basic_table_count; i++) (ctx->memfree)(ctx->arg, ctx->basic_table[i]); (ctx->memfree)(ctx->arg, ctx->freelists); (ctx->memfree)(ctx->arg, ctx->stats); (ctx->memfree)(ctx->arg, ctx->basic_table); + (void)isc_mutex_destroy(&ctx->lock); (ctx->memfree)(ctx->arg, ctx); @@ -609,6 +621,18 @@ isc_mem_strdup(isc_mem_t *mctx, const char *s) { return (ns); } +isc_boolean_t +isc_mem_destroy_check(isc_mem_t *mctx, isc_boolean_t flag) { + isc_boolean_t oldval; + + INSIST(mctx != NULL); + + oldval = mctx->checkfree; + mctx->checkfree = flag; + return (oldval); +} + + /* * Quotas */