]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMigrationParamsParse: Refactor variable cleanup
authorPeter Krempa <pkrempa@redhat.com>
Wed, 19 Aug 2020 11:20:13 +0000 (13:20 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 24 Aug 2020 14:34:51 +0000 (16:34 +0200)
Use automatic memory allocation and move variables into correct scope to
simplify the code and remove the need for a 'cleanup:' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_migration_params.c

index 9b6601367a442e531925abd810d5cc830b44b41f..38a5a91f2a65f9dcab8a494721db7813433ed8f1 100644 (file)
@@ -1265,44 +1265,42 @@ int
 qemuMigrationParamsParse(xmlXPathContextPtr ctxt,
                          qemuMigrationParamsPtr *migParams)
 {
-    qemuMigrationParamsPtr params = NULL;
+    g_autoptr(qemuMigrationParams) params = NULL;
     qemuMigrationParamValuePtr pv;
-    xmlNodePtr *nodes = NULL;
-    char *name = NULL;
-    char *value = NULL;
-    int param;
+    g_autofree xmlNodePtr *nodes = NULL;
     size_t i;
     int rc;
     int n;
-    int ret = -1;
 
     *migParams = NULL;
 
     if ((rc = virXPathBoolean("boolean(./migParams)", ctxt)) < 0)
-        goto cleanup;
+        return -1;
 
-    if (rc == 0) {
-        ret = 0;
-        goto cleanup;
-    }
+    if (rc == 0)
+        return 0;
 
     if ((n = virXPathNodeSet("./migParams[1]/param", ctxt, &nodes)) < 0)
         return -1;
 
     if (!(params = qemuMigrationParamsNew()))
-        goto cleanup;
+        return -1;
 
     for (i = 0; i < n; i++) {
+        g_autofree char *name = NULL;
+        g_autofree char *value = NULL;
+        int param;
+
         if (!(name = virXMLPropString(nodes[i], "name"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("missing migration parameter name"));
-            goto cleanup;
+            return -1;
         }
 
         if ((param = qemuMigrationParamTypeFromString(name)) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unknown migration parameter '%s'"), name);
-            goto cleanup;
+            return -1;
         }
         pv = &params->params[param];
 
@@ -1310,7 +1308,7 @@ qemuMigrationParamsParse(xmlXPathContextPtr ctxt,
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("missing value for migration parameter '%s'"),
                            name);
-            goto cleanup;
+            return -1;
         }
 
         rc = 0;
@@ -1336,23 +1334,15 @@ qemuMigrationParamsParse(xmlXPathContextPtr ctxt,
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("invalid value '%s' for migration parameter '%s'"),
                            value, name);
-            goto cleanup;
+            return -1;
         }
 
         pv->set = true;
-        VIR_FREE(name);
-        VIR_FREE(value);
     }
 
     *migParams = g_steal_pointer(&params);
-    ret = 0;
 
- cleanup:
-    qemuMigrationParamsFree(params);
-    VIR_FREE(nodes);
-    VIR_FREE(name);
-    VIR_FREE(value);
-    return ret;
+    return 0;
 }