[PATCH 07/36] qemu: driver: Automatically free temporary virBitmap-s

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

 



Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 50 ++++++++++++++----------------------------
 1 file changed, 16 insertions(+), 34 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8093b8f69b..79cfbc401c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1480,13 +1480,12 @@ qemuDomainHelperGetVcpus(virDomainObj *vm,

         if (cpumaps) {
             unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, ncpuinfo);
-            virBitmap *map = NULL;
+            g_autoptr(virBitmap) map = NULL;

             if (!(map = virProcessGetAffinity(vcpupid)))
                 return -1;

             virBitmapToDataBuf(map, cpumap, maplen);
-            virBitmapFree(map);
         }

         if (cpuwait) {
@@ -4501,7 +4500,7 @@ qemuDomainPinVcpuLive(virDomainObj *vm,
                       virQEMUDriver *driver,
                       virBitmap *cpumap)
 {
-    virBitmap *tmpmap = NULL;
+    g_autoptr(virBitmap) tmpmap = NULL;
     virDomainVcpuDef *vcpuinfo;
     qemuDomainObjPrivate *priv = vm->privateData;
     g_autoptr(virCgroup) cgroup_vcpu = NULL;
@@ -4547,8 +4546,7 @@ qemuDomainPinVcpuLive(virDomainObj *vm,
     }

     virBitmapFree(vcpuinfo->cpumask);
-    vcpuinfo->cpumask = tmpmap;
-    tmpmap = NULL;
+    vcpuinfo->cpumask = g_steal_pointer(&tmpmap);

     qemuDomainSaveStatus(vm);

@@ -4566,7 +4564,6 @@ qemuDomainPinVcpuLive(virDomainObj *vm,
     ret = 0;

  cleanup:
-    virBitmapFree(tmpmap);
     virObjectEventStateQueue(driver->domainEventState, event);
     return ret;
 }
@@ -4584,7 +4581,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
     virDomainDef *def;
     virDomainDef *persistentDef;
     int ret = -1;
-    virBitmap *pcpumap = NULL;
+    g_autoptr(virBitmap) pcpumap = NULL;
     virDomainVcpuDef *vcpuinfo = NULL;
     g_autoptr(virQEMUDriverConfig) cfg = NULL;

@@ -4628,8 +4625,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,

     if (persistentDef) {
         virBitmapFree(vcpuinfo->cpumask);
-        vcpuinfo->cpumask = pcpumap;
-        pcpumap = NULL;
+        vcpuinfo->cpumask = g_steal_pointer(&pcpumap);

         ret = virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir);
         goto endjob;
@@ -4642,7 +4638,6 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,

  cleanup:
     virDomainObjEndAPI(&vm);
-    virBitmapFree(pcpumap);
     return ret;
 }

@@ -4708,7 +4703,7 @@ qemuDomainPinEmulator(virDomainPtr dom,
     virDomainDef *persistentDef;
     int ret = -1;
     qemuDomainObjPrivate *priv;
-    virBitmap *pcpumap = NULL;
+    g_autoptr(virBitmap) pcpumap = NULL;
     g_autoptr(virQEMUDriverConfig) cfg = NULL;
     virObjectEvent *event = NULL;
     g_autofree char *str = NULL;
@@ -4791,7 +4786,6 @@ qemuDomainPinEmulator(virDomainPtr dom,

  cleanup:
     virObjectEventStateQueue(driver->domainEventState, event);
-    virBitmapFree(pcpumap);
     virDomainObjEndAPI(&vm);
     return ret;
 }
@@ -5017,7 +5011,7 @@ qemuDomainGetIOThreadsLive(virQEMUDriver *driver,
     info_ret = g_new0(virDomainIOThreadInfoPtr, niothreads);

     for (i = 0; i < niothreads; i++) {
-        virBitmap *map = NULL;
+        g_autoptr(virBitmap) map = NULL;

         info_ret[i] = g_new0(virDomainIOThreadInfo, 1);
         info_ret[i]->iothread_id = iothreads[i]->iothread_id;
@@ -5025,12 +5019,8 @@ qemuDomainGetIOThreadsLive(virQEMUDriver *driver,
         if (!(map = virProcessGetAffinity(iothreads[i]->thread_id)))
             goto endjob;

-        if (virBitmapToData(map, &info_ret[i]->cpumap,
-                            &info_ret[i]->cpumaplen) < 0) {
-            virBitmapFree(map);
+        if (virBitmapToData(map, &info_ret[i]->cpumap, &info_ret[i]->cpumaplen) < 0)
             goto endjob;
-        }
-        virBitmapFree(map);
     }

     *info = g_steal_pointer(&info_ret);
@@ -5100,7 +5090,7 @@ qemuDomainPinIOThread(virDomainPtr dom,
     virDomainObj *vm;
     virDomainDef *def;
     virDomainDef *persistentDef;
-    virBitmap *pcpumap = NULL;
+    g_autoptr(virBitmap) pcpumap = NULL;
     qemuDomainObjPrivate *priv;
     g_autoptr(virCgroup) cgroup_iothread = NULL;
     virObjectEvent *event = NULL;
@@ -5214,7 +5204,6 @@ qemuDomainPinIOThread(virDomainPtr dom,

  cleanup:
     virObjectEventStateQueue(driver->domainEventState, event);
-    virBitmapFree(pcpumap);
     virDomainObjEndAPI(&vm);
     return ret;
 }
@@ -8846,7 +8835,7 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
     int ret = -1;
     g_autoptr(virQEMUDriverConfig) cfg = NULL;
     qemuDomainObjPrivate *priv;
-    virBitmap *nodeset = NULL;
+    g_autoptr(virBitmap) nodeset = NULL;
     virDomainNumatuneMemMode config_mode;
     int mode = -1;

@@ -8953,7 +8942,6 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
     qemuDomainObjEndJob(driver, vm);

  cleanup:
-    virBitmapFree(nodeset);
     virDomainObjEndAPI(&vm);
     return ret;
 }
@@ -16579,7 +16567,7 @@ qemuDomainGetCPUStats(virDomainPtr domain,
     virDomainObj *vm = NULL;
     int ret = -1;
     qemuDomainObjPrivate *priv;
-    virBitmap *guestvcpus = NULL;
+    g_autoptr(virBitmap) guestvcpus = NULL;

     virCheckFlags(VIR_TYPED_PARAM_STRING_OKAY, -1);

@@ -16611,7 +16599,6 @@ qemuDomainGetCPUStats(virDomainPtr domain,
         ret = virCgroupGetPercpuStats(priv->cgroup, params, nparams,
                                       start_cpu, ncpus, guestvcpus);
  cleanup:
-    virBitmapFree(guestvcpus);
     virDomainObjEndAPI(&vm);
     return ret;
 }
@@ -19385,9 +19372,9 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPtr *params,
     virTypedParameterPtr par = NULL;
     int npar = 0;
     int maxpar = 0;
-    virBitmap *vcpus = virBitmapNew(QEMU_GUEST_VCPU_MAX_ID);
-    virBitmap *online = virBitmapNew(QEMU_GUEST_VCPU_MAX_ID);
-    virBitmap *offlinable = virBitmapNew(QEMU_GUEST_VCPU_MAX_ID);
+    g_autoptr(virBitmap) vcpus = virBitmapNew(QEMU_GUEST_VCPU_MAX_ID);
+    g_autoptr(virBitmap) online = virBitmapNew(QEMU_GUEST_VCPU_MAX_ID);
+    g_autoptr(virBitmap) offlinable = virBitmapNew(QEMU_GUEST_VCPU_MAX_ID);
     g_autofree char *tmp = NULL;
     size_t i;
     int ret = -1;
@@ -19424,9 +19411,6 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPtr *params,
     ret = 0;

  cleanup:
-    virBitmapFree(vcpus);
-    virBitmapFree(online);
-    virBitmapFree(offlinable);
     virTypedParamsFree(par, npar);
     return ret;
 }
@@ -19489,7 +19473,7 @@ qemuDomainSetGuestVcpus(virDomainPtr dom,
 {
     virQEMUDriver *driver = dom->conn->privateData;
     virDomainObj *vm = NULL;
-    virBitmap *map = NULL;
+    g_autoptr(virBitmap) map = NULL;
     qemuAgentCPUInfo *info = NULL;
     qemuAgent *agent;
     int ninfo = 0;
@@ -19562,7 +19546,6 @@ qemuDomainSetGuestVcpus(virDomainPtr dom,

  cleanup:
     VIR_FREE(info);
-    virBitmapFree(map);
     virDomainObjEndAPI(&vm);
     return ret;
 }
@@ -19578,7 +19561,7 @@ qemuDomainSetVcpu(virDomainPtr dom,
     virDomainObj *vm = NULL;
     virDomainDef *def = NULL;
     virDomainDef *persistentDef = NULL;
-    virBitmap *map = NULL;
+    g_autoptr(virBitmap) map = NULL;
     ssize_t lastvcpu;
     int ret = -1;

@@ -19635,7 +19618,6 @@ qemuDomainSetVcpu(virDomainPtr dom,
     qemuDomainObjEndJob(driver, vm);

  cleanup:
-    virBitmapFree(map);
     virDomainObjEndAPI(&vm);
     return ret;
 }
-- 
2.31.1




[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