[PATCH 25/40] qemuProcessUpdateDevices: Refactor cleanup and memory handling

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

 



Use automatic memory freeing and remove the 'cleanup' label. Also make
it a bit more obvious that nothing happens if the 'old' list wasn't
present.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_process.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 30cfa4d485..1fd3230e97 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3798,32 +3798,23 @@ qemuProcessUpdateDevices(virQEMUDriverPtr driver,
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virDomainDeviceDef dev;
-    const char **qemuDevices;
-    char **old;
-    char **tmp;
-    int ret = -1;
+    g_auto(GStrv) old = g_steal_pointer(&priv->qemuDevices);
+    GStrv tmp;

-    old = priv->qemuDevices;
-    priv->qemuDevices = NULL;
     if (qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
-        goto cleanup;
+        return -1;

-    qemuDevices = (const char **)priv->qemuDevices;
-    if ((tmp = old)) {
-        while (*tmp) {
-            if (!virStringListHasString(qemuDevices, *tmp) &&
-                virDomainDefFindDevice(vm->def, *tmp, &dev, false) == 0 &&
-                qemuDomainRemoveDevice(driver, vm, &dev) < 0) {
-                goto cleanup;
-            }
-            tmp++;
-        }
+    if (!old)
+        return 0;
+
+    for (tmp = old; *tmp; tmp++) {
+        if (!virStringListHasString((const char **) priv->qemuDevices, *tmp) &&
+            virDomainDefFindDevice(vm->def, *tmp, &dev, false) == 0 &&
+            qemuDomainRemoveDevice(driver, vm, &dev))
+            return -1;
     }
-    ret = 0;

- cleanup:
-    g_strfreev(old);
-    return ret;
+    return 0;
 }

 static int
-- 
2.29.2




[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