From 9f4ff7dec42f2584d1176a30d0a63e8971f715f7 Mon Sep 17 00:00:00 2001 From: Colin Vidal Date: Fri, 17 Oct 2025 10:54:09 +0200 Subject: [PATCH 1/2] mem: checkfree assertion after debug list dump When a memory context is destroyed, if the `checkfree` property is set, the program assert there is no remaining allocation. If there are and assertions are enabled, the program immediately stops. However, if memory trace/record debug is enabled, the dump of outstanding allocation won't be printed as it is done after the no remaining allocation assertion check. This moves the no remaining allocation assertion check after the dump of outstanding allocations, so it is still possible to figure out what's still allocated by this memory context. --- lib/isc/mem.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/isc/mem.c b/lib/isc/mem.c index d06a8dbb64..11d93f3ed6 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -553,14 +553,6 @@ mem_destroy(isc_mem_t *ctx) { 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 +574,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); From c50ace654d877f442cf26c2043936eb005d46889 Mon Sep 17 00:00:00 2001 From: Colin Vidal Date: Sat, 18 Oct 2025 17:44:27 +0200 Subject: [PATCH 2/2] check memory context validity before mem_destory Add a magic number check to ensure the memory context validity before destorying it. This check is needed now as it was done before implicitly when isc_mem_inuse was called, but isc_mem_inuse is now called later (to be able to dump the outstanding allocations). --- lib/isc/mem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 11d93f3ed6..7b391042d9 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -547,6 +547,8 @@ 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);