mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-26 08:02:21 +00:00
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>
This commit is contained in:
parent
5b81b9366f
commit
f4942228d2
8
utils.c
8
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;
|
||||
|
Loading…
Reference in New Issue
Block a user