[PATCH 18/23] qemuProcessSetupHotpluggableVcpus: Use automatic memory freeing

Peter Krempa pkrempa at redhat.com
Wed Aug 4 11:02:38 UTC 2021


'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 at redhat.com>
---
 src/qemu/qemu_process.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 4730d52f01..68d9de798d 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -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;
 }

-- 
2.31.1




More information about the libvir-list mailing list