[PATCH 3/5] cmdDomHostname: Fix uninitialized use of 'hostname' by refactoring cleanup

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

 



Use 'g_autoptr' which mandates initialization for 'hostname' and also
for 'domain' to allow full refactor of the cleanup path.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tools/virsh-domain.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 9d0f7d68d2..8591e483a5 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -11885,9 +11885,8 @@ VIR_ENUM_IMPL(virshDomainHostnameSource,
 static bool
 cmdDomHostname(vshControl *ctl, const vshCmd *cmd)
 {
-    char *hostname;
-    virDomainPtr dom;
-    bool ret = false;
+    g_autofree char *hostname = NULL;
+    g_autoptr(virshDomain) dom = NULL;
     const char *sourcestr = NULL;
     int flags = 0; /* Use default value. Drivers can have its own default. */

@@ -11895,14 +11894,14 @@ cmdDomHostname(vshControl *ctl, const vshCmd *cmd)
         return false;

     if (vshCommandOptStringReq(ctl, cmd, "source", &sourcestr) < 0)
-        goto error;
+        return false;

     if (sourcestr) {
         int source = virshDomainHostnameSourceTypeFromString(sourcestr);

         if (source < 0) {
             vshError(ctl, _("Unknown data source '%s'"), sourcestr);
-            goto error;
+            return false;
         }

         switch ((virshDomainHostnameSource) source) {
@@ -11920,16 +11919,11 @@ cmdDomHostname(vshControl *ctl, const vshCmd *cmd)
     hostname = virDomainGetHostname(dom, flags);
     if (hostname == NULL) {
         vshError(ctl, "%s", _("failed to get hostname"));
-        goto error;
+        return false;
     }

     vshPrint(ctl, "%s\n", hostname);
-    ret = true;
-
- error:
-    VIR_FREE(hostname);
-    virshDomainFree(dom);
-    return ret;
+    return true;
 }

 /**
-- 
2.24.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux