[PATCH 17/20] qemuMigrationCookieCapsXMLParse: Refactor memory handling

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

 



Use modern allocators, automatic memory feeing, and decrease the scope
of some variables to remove the 'cleanup' label.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_migration_cookie.c | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)

diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c
index 1e0a1c3d7f..a1ef3d2b12 100644
--- a/src/qemu/qemu_migration_cookie.c
+++ b/src/qemu/qemu_migration_cookie.c
@@ -1057,29 +1057,26 @@ qemuMigrationCookieStatisticsXMLParse(xmlXPathContextPtr ctxt)
 static qemuMigrationCookieCapsPtr
 qemuMigrationCookieCapsXMLParse(xmlXPathContextPtr ctxt)
 {
-    qemuMigrationCookieCapsPtr caps = NULL;
-    xmlNodePtr *nodes = NULL;
-    qemuMigrationCookieCapsPtr ret = NULL;
-    char *name = NULL;
-    char *automatic = NULL;
-    int cap;
+    g_autoptr(qemuMigrationCookieCaps) caps = g_new0(qemuMigrationCookieCaps, 1);
+    g_autofree xmlNodePtr *nodes = NULL;
     size_t i;
     int n;

-    if (VIR_ALLOC(caps) < 0)
-        return NULL;
-
     caps->supported = virBitmapNew(QEMU_MIGRATION_CAP_LAST);
     caps->automatic = virBitmapNew(QEMU_MIGRATION_CAP_LAST);

     if ((n = virXPathNodeSet("./capabilities[1]/cap", ctxt, &nodes)) < 0)
-        goto cleanup;
+        return NULL;

     for (i = 0; i < n; i++) {
+        g_autofree char *name = NULL;
+        g_autofree char *automatic = NULL;
+        int cap;
+
         if (!(name = virXMLPropString(nodes[i], "name"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("missing migration capability name"));
-            goto cleanup;
+            return NULL;
         }

         if ((cap = qemuMigrationCapabilityTypeFromString(name)) < 0)
@@ -1090,19 +1087,9 @@ qemuMigrationCookieCapsXMLParse(xmlXPathContextPtr ctxt)
         if ((automatic = virXMLPropString(nodes[i], "auto")) &&
             STREQ(automatic, "yes"))
             ignore_value(virBitmapSetBit(caps->automatic, cap));
-
-        VIR_FREE(name);
-        VIR_FREE(automatic);
     }

-    ret = g_steal_pointer(&caps);
-
- cleanup:
-    qemuMigrationCookieCapsFree(caps);
-    VIR_FREE(nodes);
-    VIR_FREE(name);
-    VIR_FREE(automatic);
-    return ret;
+    return g_steal_pointer(&caps);
 }


-- 
2.26.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