diff options
author | David Sterba <dsterba@suse.com> | 2015-11-06 18:52:09 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2015-11-16 14:23:44 +0100 |
commit | f4942228d25d7a63033d7db60a189f87cf08d71a (patch) | |
tree | 398e8fe4d1a0babc63ba7fcbfb4825c2fa3ebccd /utils.c | |
parent | 5b81b9366f3a501ec7d51b8d9ab6e7117c4ee96a (diff) |
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>
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -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; |