[PATCH 1/7] qemuMigrationParamsNew: Use new memory allocation to simplify code

Peter Krempa pkrempa at redhat.com
Mon Aug 24 12:05:53 UTC 2020


Use automatic memory cleaning and allocate via g_new0.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_migration_params.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 04434e9557..f466c3c4f6 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -244,20 +244,14 @@ qemuMigrationParamsGetAlwaysOnCaps(qemuMigrationParty party)
 qemuMigrationParamsPtr
 qemuMigrationParamsNew(void)
 {
-    qemuMigrationParamsPtr params;
+    g_autoptr(qemuMigrationParams) params = NULL;

-    if (VIR_ALLOC(params) < 0)
-        return NULL;
-
-    params->caps = virBitmapNew(QEMU_MIGRATION_CAP_LAST);
-    if (!params->caps)
-        goto error;
+    params = g_new0(qemuMigrationParams, 1);

-    return params;
+    if (!(params->caps = virBitmapNew(QEMU_MIGRATION_CAP_LAST)))
+        return NULL;

- error:
-    qemuMigrationParamsFree(params);
-    return NULL;
+    return g_steal_pointer(&params);
 }


-- 
2.26.2




More information about the libvir-list mailing list