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

Peter Krempa posted 7 patches 5 years, 5 months ago
[PATCH 1/7] qemuMigrationParamsNew: Use new memory allocation to simplify code
Posted by Peter Krempa 5 years, 5 months ago
Use automatic memory cleaning and allocate via g_new0.

Signed-off-by: Peter Krempa <pkrempa@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

Re: [PATCH 1/7] qemuMigrationParamsNew: Use new memory allocation to simplify code
Posted by Ján Tomko 5 years, 5 months ago
On a Monday in 2020, Peter Krempa wrote:
>Use automatic memory cleaning and allocate via g_new0.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/qemu/qemu_migration_params.c | 16 +++++-----------
> 1 file changed, 5 insertions(+), 11 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano