summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/mem-pool.c
diff options
context:
space:
mode:
authorshishir gowda <shishirng@gluster.com>2010-08-18 07:49:15 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-08-18 06:55:46 -0700
commit3c75958d1948753976405f848f59326fc1896c95 (patch)
treef66374dd0257add11eafd50ed1b6093ed4f80b37 /libglusterfs/src/mem-pool.c
parent0b890833c8cba9bac71877e528d810eba91dd1e6 (diff)
Fix memory corruption in mem pool
Added new interface mem_get0, which calls memset on the mem pool entries being returned. Gluster and Kernel compile should now succeed. Signed-off-by: shishir gowda <shishirng@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1393 (Gluster and kernel compile fails) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1393
Diffstat (limited to 'libglusterfs/src/mem-pool.c')
-rw-r--r--libglusterfs/src/mem-pool.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index f1a2c98de..aec1d909d 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -337,6 +337,41 @@ mem_pool_new_fn (unsigned long sizeof_type,
return mem_pool;
}
+void*
+mem_get0 (struct mem_pool *mem_pool)
+{
+ struct list_head *list = NULL;
+ void *ptr = NULL;
+
+ if (!mem_pool) {
+ gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
+ return NULL;
+ }
+
+ LOCK (&mem_pool->lock);
+ {
+ if (mem_pool->cold_count) {
+ list = mem_pool->list.next;
+ list_del (list);
+
+ mem_pool->hot_count++;
+ mem_pool->cold_count--;
+
+ ptr = list;
+ goto fwd_addr_out;
+ }
+ ptr = MALLOC (mem_pool->real_sizeof_type);
+ goto unlocked_out;
+ }
+fwd_addr_out:
+ ptr = mem_pool_chunkhead2ptr (ptr);
+unlocked_out:
+
+ memset(ptr, 0, mem_pool->real_sizeof_type);
+ UNLOCK (&mem_pool->lock);
+
+ return ptr;
+}
void *
mem_get (struct mem_pool *mem_pool)