[sheepdog] [PATCH v1] sheep/gateway: fix memory leak in prepare_erasure_requests()

Bingpeng Zhu nkuzbp at foxmail.com
Mon May 11 14:25:41 CEST 2015


In prepare_erasure_requests(), when init_erasure_buffer() returns NULL,
we should release buffers of requests which are allocated via xmalloc().

Signed-off-by: Bingpeng Zhu <bingpeng.zbp at alibaba-inc.com>
---
 sheep/gateway.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/sheep/gateway.c b/sheep/gateway.c
index 89db9bf..3cb21f0 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -152,6 +152,8 @@ static struct req_iter *prepare_erasure_requests(struct request *req, int *nr)
 	if (!buf) {
 		sd_err("failed to init erasure buffer %"PRIx64,
 		       req->rq.obj.oid);
+		for (i = 0; i < nr_to_send; i++)
+			free(reqs[i].buf);
 		free(reqs);
 		reqs = NULL;
 		goto out;
-- 
1.7.1







More information about the sheepdog mailing list