[sheepdog] [PATCH 1/6] sheep: use xmalloc instead of malloc

Liu Yuan namei.unix at gmail.com
Mon Apr 22 17:34:10 CEST 2013


From: Liu Yuan <tailai.ly at taobao.com>

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/vdi.c |   29 ++++-------------------------
 1 file changed, 4 insertions(+), 25 deletions(-)

diff --git a/sheep/vdi.c b/sheep/vdi.c
index 5f23846..e4d3c9e 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -311,12 +311,7 @@ static int find_first_vdi(unsigned long start, unsigned long end,
 	bool vdi_found = false;
 	int nr_copies;
 
-	inode = malloc(SD_INODE_HEADER_SIZE);
-	if (!inode) {
-		sd_eprintf("failed to allocate memory");
-		goto out;
-	}
-
+	inode = xmalloc(SD_INODE_HEADER_SIZE);
 	for (i = start; i >= end; i--) {
 		nr_copies = get_vdi_copy_number(i);
 		ret = read_object(vid_to_vdi_oid(i), (char *)inode,
@@ -369,7 +364,6 @@ static int find_first_vdi(unsigned long start, unsigned long end,
 
 out_free_inode:
 	free(inode);
-out:
 	return ret;
 }
 
@@ -619,12 +613,7 @@ static void delete_one(struct work *work)
 
 	sd_dprintf("%d %d, %16x", dw->done, dw->count, vdi_id);
 
-	inode = malloc(sizeof(*inode));
-	if (!inode) {
-		sd_eprintf("failed to allocate memory");
-		goto out;
-	}
-
+	inode = xmalloc(sizeof(*inode));
 	nr_copies = get_vdi_copy_number(vdi_id);
 	ret = read_backend_object(vid_to_vdi_oid(vdi_id),
 			  (void *)inode, sizeof(*inode), 0, nr_copies);
@@ -708,12 +697,7 @@ static int fill_vdi_list(struct deletion_work *dw, uint32_t root_vid)
 	uint32_t vid;
 	int nr_copies;
 
-	inode = malloc(SD_INODE_HEADER_SIZE);
-	if (!inode) {
-		sd_eprintf("failed to allocate memory");
-		goto err;
-	}
-
+	inode = xmalloc(SD_INODE_HEADER_SIZE);
 	dw->buf[dw->count++] = root_vid;
 again:
 	vid = dw->buf[done++];
@@ -753,12 +737,7 @@ static uint64_t get_vdi_root(uint32_t vid, bool *cloned)
 
 	*cloned = false;
 
-	inode = malloc(SD_INODE_HEADER_SIZE);
-	if (!inode) {
-		sd_eprintf("failed to allocate memory");
-		vid = 0;
-		goto out;
-	}
+	inode = xmalloc(SD_INODE_HEADER_SIZE);
 next:
 	nr_copies = get_vdi_copy_number(vid);
 	ret = read_backend_object(vid_to_vdi_oid(vid), (char *)inode,
-- 
1.7.9.5




More information about the sheepdog mailing list