From 333474e0d6efe1a2b3a9ecffc9bdff3e49325910 Mon Sep 17 00:00:00 2001 From: Zhou Zhengping Date: Tue, 9 May 2017 20:57:34 +0800 Subject: libglusterfs: fix race condition in client_ctx_set follow procedures: 1.thread1 client_ctx_get return NULL 2.thread 2 client_ctx_set ctx1 ok 3.thread1 client_ctx_set ctx2 ok thread1 use ctx1, thread2 use ctx2 and ctx1 will leak Change-Id: I990b02905edd1b3179323ada56888f852d20f538 BUG: 1449232 Signed-off-by: Zhou Zhengping Reviewed-on: https://review.gluster.org/17219 NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Raghavendra G Smoke: Gluster Build System Reviewed-by: Jeff Darcy --- xlators/performance/io-threads/src/io-threads.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'xlators/performance/io-threads') diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c index fd860d6a133..1247e41c99e 100644 --- a/xlators/performance/io-threads/src/io-threads.c +++ b/xlators/performance/io-threads/src/io-threads.c @@ -52,6 +52,7 @@ iot_client_ctx_t * iot_get_ctx (xlator_t *this, client_t *client) { iot_client_ctx_t *ctx = NULL; + iot_client_ctx_t *setted_ctx = NULL; int i; if (client_ctx_get (client, this, (void **)&ctx) != 0) { @@ -62,9 +63,10 @@ iot_get_ctx (xlator_t *this, client_t *client) INIT_LIST_HEAD (&ctx[i].clients); INIT_LIST_HEAD (&ctx[i].reqs); } - if (client_ctx_set (client, this, ctx) != 0) { + setted_ctx = client_ctx_set (client, this, ctx); + if (ctx != setted_ctx) { GF_FREE (ctx); - ctx = NULL; + ctx = setted_ctx; } } } -- cgit