[sheepdog] [PATCH] zookeeper: fix random segfault due to uninitialized allocation

Liu Yuan namei.unix at gmail.com
Fri Jan 4 08:50:05 CET 2013


From: Liu Yuan <tailai.ly at taobao.com>

The gone filed should be false or it will cause random segfault.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/cluster/zookeeper.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 3274077..6e03385 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -325,7 +325,7 @@ static int zk_member_empty(void)
 
 static inline void zk_tree_add(struct zk_node *node)
 {
-	struct zk_node *zk = malloc(sizeof(*zk));
+	struct zk_node *zk = xzalloc(sizeof(*zk));
 	*zk = *node;
 	pthread_rwlock_wrlock(&zk_tree_lock);
 	if (zk_tree_insert(zk)) {
@@ -666,11 +666,10 @@ static void zk_handle_leave(struct zk_event *ev)
 
 static void zk_handle_block(struct zk_event *ev)
 {
-	struct zk_node *block = xmalloc(sizeof(*block));
+	struct zk_node *block = xzalloc(sizeof(*block));
 
 	dprintf("BLOCK\n");
 	block->node = ev->sender.node;
-	block->callbacked = false;
 	list_add_tail(&block->list, &zk_block_list);
 	block = list_first_entry(&zk_block_list, typeof(*block), list);
 	if (!block->callbacked)
-- 
1.7.9.5




More information about the sheepdog mailing list