From 38bfe5050847509c2ba8883c004f0c3f6383a155 Mon Sep 17 00:00:00 2001 From: Stathis Voukelatos Date: Thu, 17 Jan 2013 16:52:47 +0000 Subject: [PATCH] Fixed size calculation in MALLOC memory pool creation macro. The LWIP_MALLOC_MEMPOOL macro needs to use the aligned size of the memp_malloc_helper structure, since mem_alloc() uses it to calculate the required pool element size. If LWIP_MEM_ALIGN_SIZE(x) is redefined to align to something larger than 4, then in some cases the current code can lead to unexpected mem_alloc() failures. For example: #define LWIP_MEM_ALIGN_SIZE(size) (((size) + 31) & ~31) and the largest MALLOC pool is of size 60 bytes, e.g.: #define LWIP_MALLOC_MEMPOOL(256, 60) then the following call: mem_malloc(58) will cause an assertion. --- src/include/lwip/memp_std.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/lwip/memp_std.h b/src/include/lwip/memp_std.h index 592a2824..8e1c99c4 100644 --- a/src/include/lwip/memp_std.h +++ b/src/include/lwip/memp_std.h @@ -12,7 +12,7 @@ #ifndef LWIP_MALLOC_MEMPOOL /* This treats "malloc pools" just like any other pool. The pools are a little bigger to provide 'size' as the amount of user data. */ -#define LWIP_MALLOC_MEMPOOL(num, size) LWIP_MEMPOOL(POOL_##size, num, (size + sizeof(struct memp_malloc_helper)), "MALLOC_"#size) +#define LWIP_MALLOC_MEMPOOL(num, size) LWIP_MEMPOOL(POOL_##size, num, (size + LWIP_MEM_ALIGN_SIZE(sizeof(struct memp_malloc_helper))), "MALLOC_"#size) #define LWIP_MALLOC_MEMPOOL_START #define LWIP_MALLOC_MEMPOOL_END #endif /* LWIP_MALLOC_MEMPOOL */