From 3737ed53caad69ddb0f5b3db2e3498c2d7df2dff Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Fri, 18 Aug 2017 17:12:05 +0200 Subject: mempool: fix code when GF_DISABLE_MEMPOOL is defined Problem: Run-time crash is observed when attempting to memset() a zero length buffer. Solution: When GF_DISABLE_MEMPOOL is set, mem_get() gets translated to a GF_MALLOC(). The size of the allocation does not need to relate to the available (but uninitialized) global memory pools. It is fine to allocate the exact amount of memory that was configured when the mem-pool was created. Change-Id: Iea0bff974bb771623a34d7a940e10cb0db0f90e1 BUG: 1481199 Reported-by: Milind Changire Signed-off-by: Niels de Vos Reviewed-on: https://review.gluster.org/18034 Smoke: Gluster Build System CentOS-regression: Gluster Build System Reviewed-by: Jeff Darcy --- libglusterfs/src/mem-pool.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index 4d2c324baa2..a2889146a5b 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -689,9 +689,12 @@ mem_get0 (struct mem_pool *mem_pool) } ptr = mem_get(mem_pool); - if (ptr) { +#if defined(GF_DISABLE_MEMPOOL) + memset (ptr, 0, mem_pool->sizeof_type); +#else memset (ptr, 0, AVAILABLE_SIZE(mem_pool->pool->power_of_two)); +#endif } return ptr; @@ -770,8 +773,7 @@ void * mem_get (struct mem_pool *mem_pool) { #if defined(GF_DISABLE_MEMPOOL) - return GF_CALLOC (1, AVAILABLE_SIZE (mem_pool->pool->power_of_two), - gf_common_mt_mem_pool); + return GF_MALLOC (mem_pool->sizeof_type, gf_common_mt_mem_pool); #else per_thread_pool_list_t *pool_list; per_thread_pool_t *pt_pool; -- cgit