[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] btrfs_balance_status: delay allocation of 'ret'



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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]