Subject: [PATCH v4 4/8] mem-pool: tweak math on mp_block allocation size

From: Jameson Miller <[email-masked]>
Date: Wed, 20 Jun 2018 20:17:28 +0000

The amount of memory to allocate for mp_blocks was off by a
sizeof(uintmax_t) on platforms that do not support flexible arrays. To
account for this, use the offset of the space field when calculating
the total amount of memory to allocate for a mp_block.

Signed-off-by: Jameson Miller <[email-masked]>
---
 mem-pool.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mem-pool.c b/mem-pool.c
index c80124f1fe..a5d5eed923 100644
--- a/mem-pool.c
+++ b/mem-pool.c
@@ -8,9 +8,11 @@
 static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_pool, size_t block_alloc)
 {
 	struct mp_block *p;
+	size_t total_alloc = st_add(offsetof(struct mp_block, space), block_alloc);
+
+	mem_pool->pool_alloc = st_add(mem_pool->pool_alloc, total_alloc);
+	p = xmalloc(total_alloc);
 
-	mem_pool->pool_alloc += sizeof(struct mp_block) + block_alloc;
-	p = xmalloc(st_add(sizeof(struct mp_block), block_alloc));
 	p->next_block = mem_pool->mp_block;
 	p->next_free = (char *)p->space;
 	p->end = p->next_free + block_alloc;
-- 
2.14.3