btrfs_balance_status: delay allocation of 'ret'

Allocate 'ret' as late as possible, so there is no risk that early
returns will leak it.

(cherry picked from commit 31ee088812)
This commit is contained in:
Pino Toscano
2018-08-06 15:36:46 +02:00
committed by Richard W.M. Jones
parent 961c37995e
commit 8d5f54b45c

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) {