On Mon, Aug 06, 2018 at 04:06:55PM +0200, Pino Toscano wrote:
Allocate 'ret' as late as possible, so there is no risk that
early
returns will leak it.
---
daemon/btrfs.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 26757d4fb..5c4be6cf7 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -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) {
--
2.17.1
ACK, thanks.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW