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

[libvirt] [PATCH 4/4] conf: Clean up and report error in virDomainGenerateMachineName



Signed-off-by: Martin Kletzander <mkletzan redhat com>
---
 src/conf/domain_conf.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3bef5bed3b4a..fffdeb353581 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -27151,25 +27151,23 @@ virDomainGenerateMachineName(const char *drivername,
                              const char *name,
                              bool privileged)
 {
-    char *machinename = NULL;
     char *username = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
 
     if (privileged) {
         virBufferAsprintf(&buf, "%s-", drivername);
     } else {
-        if (!(username = virGetUserName(geteuid())))
-            goto cleanup;
-
+        if (!(username = virGetUserName(geteuid()))) {
+            virBufferFreeAndReset(&buf);
+            return NULL;
+        }
         virBufferAsprintf(&buf, "%s-%s-", username, drivername);
+        VIR_FREE(username);
     }
 
     virBufferAsprintf(&buf, "%d-", id);
     virDomainMachineNameAppendValid(&buf, name);
 
-    machinename = virBufferContentAndReset(&buf);
- cleanup:
-    VIR_FREE(username);
-
-    return machinename;
+    virBufferCheckError(&buf);
+    return virBufferContentAndReset(&buf);
 }
-- 
2.14.1


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