summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorNiels de Vos <ndevos@redhat.com>2017-08-18 17:12:05 +0200
committerJeff Darcy <jeff@pl.atyp.us>2017-09-02 02:21:15 +0000
commit3737ed53caad69ddb0f5b3db2e3498c2d7df2dff (patch)
treea0ff5871403fc4b42de675b6814c8d45cb5eb29d /libglusterfs
parentd7ccdb33c2e84bab25bf0898866104f8a85b4217 (diff)
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 <mchangir@redhat.com> Signed-off-by: Niels de Vos <ndevos@redhat.com> Reviewed-on: https://review.gluster.org/18034 Smoke: Gluster Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/mem-pool.c8
1 files changed, 5 insertions, 3 deletions
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;