]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
contrib/ucw/mempool: add chunk to pool reference in debug mode
authorLukáš Ondráček <lukas.ondracek@nic.cz>
Thu, 4 Jun 2026 14:25:08 +0000 (16:25 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Wed, 8 Jul 2026 11:38:26 +0000 (13:38 +0200)
src/contrib/ucw/mempool.c

index 47bf2da5475a5fb4a3d024969fc9c359ccf37c61..173692c0ae13cb1bcd7f4b565186b1c3974a3e79 100644 (file)
@@ -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;