[sheepdog] [PATCH] sheep/request: fix potential incorrect cluster info refcnt

Ruoyu liangry at ucweb.com
Thu Jul 10 08:29:39 CEST 2014


For fear that req->data is not allocated successfully, move
increament of cluster info refcnt after memory alloc is reasonable.

Signed-off-by: Ruoyu <liangry at ucweb.com>
---
 sheep/request.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sheep/request.c b/sheep/request.c
index f2ccff6..eb72b00 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -687,8 +687,6 @@ static struct request *alloc_request(struct client_info *ci, int data_length)
 	if (!req)
 		return NULL;
 
-	req->ci = ci;
-	refcount_inc(&ci->refcnt);
 	if (data_length) {
 		req->data_length = data_length;
 		req->data = valloc(data_length);
@@ -698,6 +696,9 @@ static struct request *alloc_request(struct client_info *ci, int data_length)
 		}
 	}
 
+	req->ci = ci;
+	refcount_inc(&ci->refcnt);
+
 	refcount_set(&req->refcnt, 1);
 
 	uatomic_inc(&sys->nr_outstanding_reqs);
-- 
1.8.3.2





More information about the sheepdog mailing list