From: Lukáš Ondráček Date: Thu, 4 Jun 2026 14:25:08 +0000 (+0200) Subject: contrib/ucw/mempool: add chunk to pool reference in debug mode X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb884e8e383eaf82c80fc8d3ddb8ea1d166c4e1a;p=thirdparty%2Fknot-dns.git contrib/ucw/mempool: add chunk to pool reference in debug mode --- diff --git a/src/contrib/ucw/mempool.c b/src/contrib/ucw/mempool.c index 47bf2da547..173692c0ae 100644 --- a/src/contrib/ucw/mempool.c +++ b/src/contrib/ucw/mempool.c @@ -60,6 +60,9 @@ page_free(void *start, uint64_t len) #endif struct mempool_chunk { +#ifdef CONFIG_DEBUG + struct mempool *pool; // Can be useful when analysing coredump for memory leaks +#endif struct mempool_chunk *next; size_t size; }; @@ -144,6 +147,9 @@ mp_new(size_t chunk_size) ASAN_UNPOISON_MEMORY_REGION(pool, sizeof(*pool)); DBG("Creating mempool %p with %zu bytes long chunks", pool, chunk_size); chunk->next = NULL; +#ifdef CONFIG_DEBUG + chunk->pool = pool; +#endif ASAN_POISON_MEMORY_REGION(chunk, sizeof(struct mempool_chunk)); *pool = (struct mempool) { .state = { .free = { chunk_size - sizeof(*pool) }, .last = { chunk } }, @@ -268,6 +274,9 @@ mp_alloc_internal(struct mempool *pool, size_t size) pool->unused = chunk->next; } else { chunk = mp_new_chunk(pool->chunk_size); +#ifdef CONFIG_DEBUG + chunk->pool = pool; +#endif } chunk->next = pool->state.last[0]; ASAN_POISON_MEMORY_REGION(chunk, sizeof(struct mempool_chunk)); @@ -282,6 +291,10 @@ mp_alloc_internal(struct mempool *pool, size_t size) return NULL; } chunk->next = pool->state.last[1]; +#ifdef CONFIG_DEBUG + chunk->pool = pool; +#endif + ASAN_POISON_MEMORY_REGION(chunk, sizeof(struct mempool_chunk)); pool->state.last[1] = chunk; pool->state.free[1] = aligned - size;