[sheepdog] [PATCH] sheep: fix memory leaks at start_deletion()

Ryusuke Konishi konishi.ryusuke at lab.ntt.co.jp
Mon Dec 16 15:00:18 CET 2013


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>
---
 sheep/vdi.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sheep/vdi.c b/sheep/vdi.c
index 7c4ca78..eca4f43 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -1075,7 +1075,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);
@@ -1091,12 +1091,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;
 
@@ -1107,9 +1109,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.9.3




More information about the sheepdog mailing list