[libvirt PATCH 16/20] vmware: refactor vmwareUpdateVMStatus

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

 



Use g_auto and get rid of the cleanup label, as well as the ret
variable.

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/vmware/vmware_driver.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index 8f107dd529..998ecdb546 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -284,27 +284,26 @@ vmwareConnectGetVersion(virConnectPtr conn, unsigned long *version)
 static int
 vmwareUpdateVMStatus(struct vmware_driver *driver, virDomainObj *vm)
 {
-    virCommand *cmd;
-    char *outbuf = NULL;
-    char *vmxAbsolutePath = NULL;
+    g_autoptr(virCommand) cmd = NULL;
+    g_autofree char *outbuf = NULL;
+    g_autofree char *vmxAbsolutePath = NULL;
     char *parsedVmxPath = NULL;
     char *str;
     char *saveptr = NULL;
     bool found = false;
     int oldState = virDomainObjGetState(vm, NULL);
     int newState;
-    int ret = -1;
 
     cmd = virCommandNewArgList(driver->vmrun, "-T",
                                vmwareDriverTypeToString(driver->type),
                                "list", NULL);
     virCommandSetOutputBuffer(cmd, &outbuf);
     if (virCommandRun(cmd, NULL) < 0)
-        goto cleanup;
+        return -1;
 
     if (virFileResolveAllLinks(((vmwareDomainPtr) vm->privateData)->vmxPath,
                                &vmxAbsolutePath) < 0)
-        goto cleanup;
+        return -1;
 
     for (str = outbuf; (parsedVmxPath = strtok_r(str, "\n", &saveptr)) != NULL;
          str = NULL) {
@@ -331,13 +330,7 @@ vmwareUpdateVMStatus(struct vmware_driver *driver, virDomainObj *vm)
 
     virDomainObjSetState(vm, newState, 0);
 
-    ret = 0;
-
- cleanup:
-    virCommandFree(cmd);
-    VIR_FREE(outbuf);
-    VIR_FREE(vmxAbsolutePath);
-    return ret;
+    return 0;
 }
 
 static int
-- 
2.31.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