[sheepdog-users] [PATCH stable-0.7 2/4] sheep: fix memory leaks at start_deletion()

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Tue Dec 17 09:52:38 CET 2013


From: Ryusuke Konishi <konishi.ryusuke at lab.ntt.co.jp>

The start_deletion function does not free the deletion_work structure
nor the buffer (dw->buf) that it locally allocated when it deletes
inode of the VDI or dw->count was equal to zero.

This fixes these leak bugs.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke at lab.ntt.co.jp>
Reviewed-by:Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 sheep/vdi.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sheep/vdi.c b/sheep/vdi.c
index 1e05e4f..2252702 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -830,7 +830,7 @@ static int start_deletion(struct request *req, uint32_t vid)
 	root_vid = get_vdi_root(dw->vid, &cloned);
 	if (!root_vid) {
 		ret = SD_RES_EIO;
-		goto err;
+		goto out;
 	}
 
 	ret = fill_vdi_list(dw, root_vid);
@@ -846,12 +846,14 @@ static int start_deletion(struct request *req, uint32_t vid)
 			sd_debug("snapshot chain has valid vdi, just mark vdi %"
 				 PRIx32 " as deleted.", dw->vid);
 			delete_inode(dw);
-			return SD_RES_SUCCESS;
+			ret = SD_RES_SUCCESS;
+			goto out;
 		}
 	}
 
 	sd_debug("%d", dw->count);
 
+	ret = SD_RES_SUCCESS;
 	if (dw->count == 0)
 		goto out;
 
@@ -862,9 +864,9 @@ static int start_deletion(struct request *req, uint32_t vid)
 		queue_work(sys->deletion_wqueue, &dw->work);
 	} else
 		list_add_tail(&dw->list, &deletion_work_list);
+
+	return ret;
 out:
-	return SD_RES_SUCCESS;
-err:
 	if (dw)
 		free(dw->buf);
 	free(dw);
-- 
1.7.10.4




More information about the sheepdog-users mailing list