[sheepdog] [PATCH v1 1/2] dog: memory leak in vdi_object_map

Meng An isolate000 at gmail.com
Wed Jul 23 06:39:33 CEST 2014


From: meng an <isolate000 at gmail.com>

In function vdi_object_map, the pointer 'inode' is allocated via
xmalloc, but its memory is not released when returns.

Signed-off-by: Meng An <anmeng.an at alibaba-inc.com>
---
 dog/vdi.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/dog/vdi.c b/dog/vdi.c
index 9fc1677..30739ff 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -864,15 +864,14 @@ static int vdi_object_map(int argc, char **argv)
 	uint64_t idx = vdi_cmd_data.index;
 	struct sd_inode *inode = xmalloc(sizeof(*inode));
 	uint32_t vid;
-	int ret;
+	int ret = EXIT_SUCCESS;
 
 	ret = read_vdi_obj(vdiname, vdi_cmd_data.snapshot_id,
 			   vdi_cmd_data.snapshot_tag, NULL, inode,
 			   SD_INODE_SIZE);
 	if (ret != EXIT_SUCCESS) {
 		sd_err("FATAL: %s not found", vdiname);
-		free(inode);
-		return ret;
+		goto out;
 	}
 
 	printf("Index       VID\n");
@@ -888,7 +887,10 @@ static int vdi_object_map(int argc, char **argv)
 				printf("%08"PRIu64" %8"PRIx32"\n", idx, vid);
 		}
 	}
-	return EXIT_SUCCESS;
+
+out:
+	free(inode);
+	return ret;
 }
 
 static void print_expected_location(uint64_t oid, int copies)
-- 
1.7.1




More information about the sheepdog mailing list