[sheepdog] [PATCH] fix two tricky bugs

Robin Dong robin.k.dong at gmail.com
Wed Jan 1 10:30:15 CET 2014


From: Robin Dong <sanbai at taobao.com>

First bug, we should use argument 'vdi_inuse' for dog_exec_req() in parse_vdi()
because 'vdi_inuse' is already the address of a memory-space. It will cause
data corruption in some non-x86_64 machines.

Second bug, we  use 'goto out' in kv_create_object to avoid memory leak for
'onode'.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 dog/common.c    | 2 +-
 sheep/http/kv.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/dog/common.c b/dog/common.c
index 546690a..828ed1d 100644
--- a/dog/common.c
+++ b/dog/common.c
@@ -141,7 +141,7 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
 	sd_init_req(&req, SD_OP_READ_VDIS);
 	req.data_length = sizeof(vdi_inuse);
 
-	ret = dog_exec_req(&sd_nid, &req, &vdi_inuse);
+	ret = dog_exec_req(&sd_nid, &req, vdi_inuse);
 	if (ret < 0)
 		goto out;
 	if (rsp->result != SD_RES_SUCCESS) {
diff --git a/sheep/http/kv.c b/sheep/http/kv.c
index 31c9889..dd5ca56 100644
--- a/sheep/http/kv.c
+++ b/sheep/http/kv.c
@@ -1027,7 +1027,7 @@ int kv_create_object(struct http_request *req, const char *account,
 	snprintf(vdi_name, SD_MAX_VDI_LEN, "%s/%s/allocator", account, bucket);
 	ret = sd_lookup_vdi(vdi_name, &data_vid);
 	if (ret != SD_RES_SUCCESS)
-		return ret;
+		goto out;
 
 	memset(onode, 0, sizeof(*onode));
 	pstrcpy(onode->name, sizeof(onode->name), name);
-- 
1.7.12.4




More information about the sheepdog mailing list