btrfs_balance_status: delay allocation of 'ret'

Allocate 'ret' as late as possible, so there is no risk that early
returns will leak it.
This commit is contained in:
Pino Toscano
2018-08-06 15:36:46 +02:00
parent c4a0d64f63
commit 31ee088812

View File

@@ -1683,12 +1683,6 @@ do_btrfs_balance_status (const char *path)
nlines = guestfs_int_count_strings (lines);
ret = calloc (1, sizeof *ret);
if (ret == NULL) {
reply_with_perror ("calloc");
return NULL;
}
/* Output of `btrfs balance status' is like:
*
* running:
@@ -1711,6 +1705,12 @@ do_btrfs_balance_status (const char *path)
return NULL;
}
ret = calloc (1, sizeof *ret);
if (ret == NULL) {
reply_with_perror ("calloc");
return NULL;
}
if (strstr (lines[0], "No balance found on")) {
ret->btrfsbalance_status = strdup ("none");
if (ret->btrfsbalance_status == NULL) {