]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMigrationParamsToJSON: Refactor variable cleanup
authorPeter Krempa <pkrempa@redhat.com>
Wed, 19 Aug 2020 11:18:31 +0000 (13:18 +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 'error:' label.

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

index 3ed55c2ab45a72d5e7b7b72d5967f008c9213ed7..c22362735a9698201e3dcbb9397c2293c9aaaec5 100644 (file)
@@ -718,20 +718,17 @@ qemuMigrationParamsFromJSON(virJSONValuePtr params)
 virJSONValuePtr
 qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams)
 {
-    virJSONValuePtr params = virJSONValueNewObject();
-    qemuMigrationParamValuePtr pv;
-    const char *name;
+    g_autoptr(virJSONValue) params = virJSONValueNewObject();
     size_t i;
-    int rc;
 
     for (i = 0; i < QEMU_MIGRATION_PARAM_LAST; i++) {
-        name = qemuMigrationParamTypeToString(i);
-        pv = &migParams->params[i];
+        const char *name = qemuMigrationParamTypeToString(i);
+        qemuMigrationParamValuePtr pv = &migParams->params[i];
+        int rc = 0;
 
         if (!pv->set)
             continue;
 
-        rc = 0;
         switch (qemuMigrationParamTypes[i]) {
         case QEMU_MIGRATION_PARAM_TYPE_INT:
             rc = virJSONValueObjectAppendNumberInt(params, name, pv->value.i);
@@ -751,14 +748,10 @@ qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams)
         }
 
         if (rc < 0)
-            goto error;
+            return NULL;
     }
 
-    return params;
-
- error:
-    virJSONValueFree(params);
-    return NULL;
+    return g_steal_pointer(&params);
 }