btrfs-progs: mkfs: handler memory allocation error in make_btrfs

Do the allocation early, no need to cleanup.

Signed-off-by: David Sterba <dsterba@suse.com>
master
David Sterba 2015-11-06 18:52:09 +01:00
parent 5b81b9366f
commit f4942228d2
1 changed files with 5 additions and 3 deletions

View File

@ -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;