diff --git a/lib/isc/mem.c b/lib/isc/mem.c index d06a8dbb64..7b391042d9 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -547,20 +547,14 @@ mem_create(const char *name, isc_mem_t **ctxp, unsigned int debugging, static void mem_destroy(isc_mem_t *ctx) { + REQUIRE(VALID_CONTEXT(ctx)); + isc_refcount_destroy(&ctx->references); LOCK(&contextslock); ISC_LIST_UNLINK(contexts, ctx, link); UNLOCK(&contextslock); - if (ctx->checkfree) { - INSIST(isc_mem_inuse(ctx) == 0); - } - - ctx->magic = 0; - - INSIST(ISC_LIST_EMPTY(ctx->pools)); - #if ISC_MEM_TRACKLINES if (ctx->debuglist != NULL) { for (size_t i = 0; i < DEBUG_TABLE_COUNT; i++) { @@ -582,6 +576,14 @@ mem_destroy(isc_mem_t *ctx) { } #endif /* if ISC_MEM_TRACKLINES */ + if (ctx->checkfree) { + INSIST(isc_mem_inuse(ctx) == 0); + } + + ctx->magic = 0; + + INSIST(ISC_LIST_EMPTY(ctx->pools)); + free(ctx->name); isc_mutex_destroy(&ctx->lock);