]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuProcessSetupHotpluggableVcpus: Use automatic memory freeing
authorPeter Krempa <pkrempa@redhat.com>
Wed, 4 Aug 2021 09:33:35 +0000 (11:33 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 6 Aug 2021 06:53:26 +0000 (08:53 +0200)
'bootHotplug' can be auto-freed when terminating the function and moving
the declaration of 'vcpuprops' to the loop which uses it along with
automatic freeing allows us to simplify cleanup in certain cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_process.c

index a127250850e19fe97734ce999d145aa449b07d97..81af4f1a44596aad6797ceb2c68ea7eba7e0bda6 100644 (file)
@@ -5985,12 +5985,11 @@ qemuProcessSetupHotpluggableVcpus(virQEMUDriver *driver,
     qemuCgroupEmulatorAllNodesData *emulatorCgroup = NULL;
     virDomainVcpuDef *vcpu;
     qemuDomainVcpuPrivate *vcpupriv;
-    virJSONValue *vcpuprops = NULL;
     size_t i;
     int ret = -1;
     int rc;
 
-    virDomainVcpuDef **bootHotplug = NULL;
+    g_autofree virDomainVcpuDef **bootHotplug = NULL;
     size_t nbootHotplug = 0;
 
     for (i = 0; i < maxvcpus; i++) {
@@ -6005,10 +6004,8 @@ qemuProcessSetupHotpluggableVcpus(virQEMUDriver *driver,
         }
     }
 
-    if (nbootHotplug == 0) {
-        ret = 0;
-        goto cleanup;
-    }
+    if (nbootHotplug == 0)
+        return 0;
 
     qsort(bootHotplug, nbootHotplug, sizeof(*bootHotplug),
           qemuProcessVcpusSortOrder);
@@ -6017,6 +6014,7 @@ qemuProcessSetupHotpluggableVcpus(virQEMUDriver *driver,
         goto cleanup;
 
     for (i = 0; i < nbootHotplug; i++) {
+        g_autoptr(virJSONValue) vcpuprops = NULL;
         vcpu = bootHotplug[i];
 
         if (!(vcpuprops = qemuBuildHotpluggableCPUProps(vcpu)))
@@ -6033,16 +6031,12 @@ qemuProcessSetupHotpluggableVcpus(virQEMUDriver *driver,
 
         if (rc < 0)
             goto cleanup;
-
-        virJSONValueFree(vcpuprops);
     }
 
     ret = 0;
 
  cleanup:
     qemuCgroupEmulatorAllNodesRestore(emulatorCgroup);
-    VIR_FREE(bootHotplug);
-    virJSONValueFree(vcpuprops);
     return ret;
 }