From f4942228d25d7a63033d7db60a189f87cf08d71a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 6 Nov 2015 18:52:09 +0100 Subject: btrfs-progs: mkfs: handler memory allocation error in make_btrfs Do the allocation early, no need to cleanup. Signed-off-by: David Sterba --- utils.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils.c b/utils.c index 9c7cb892..17f47574 100644 --- a/utils.c +++ b/utils.c @@ -182,7 +182,7 @@ int test_uuid_unique(char *fs_uuid) int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) { struct btrfs_super_block super; - struct extent_buffer *buf = NULL; + struct extent_buffer *buf; struct btrfs_root_item root_item; struct btrfs_disk_key disk_key; struct btrfs_extent_item *extent_item; @@ -204,6 +204,10 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA); u64 num_bytes; + buf = malloc(sizeof(*buf) + max(cfg->sectorsize, cfg->nodesize)); + if (!buf) + return -ENOMEM; + first_free = BTRFS_SUPER_INFO_OFFSET + cfg->sectorsize * 2 - 1; first_free &= ~((u64)cfg->sectorsize - 1); @@ -249,8 +253,6 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) if (cfg->label) strncpy(super.label, cfg->label, BTRFS_LABEL_SIZE - 1); - buf = malloc(sizeof(*buf) + max(cfg->sectorsize, cfg->nodesize)); - /* create the tree of root objects */ memset(buf->data, 0, cfg->nodesize); buf->len = cfg->nodesize; -- cgit v1.2.3