[PATCH 7/7] qemu_capabilities.c: use g_autoptr() in virQEMUCapsInitHostCPUModel()

Ján Tomko jtomko at redhat.com
Thu Nov 18 15:15:26 UTC 2021


On a Thursday in 2021, Daniel Henrique Barboza wrote:
>All 'virCPUDef' pointers can be auto-freed and the 'cleanup' label
>removed.
>
>Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
>---
> src/qemu/qemu_capabilities.c | 21 ++++++++-------------
> 1 file changed, 8 insertions(+), 13 deletions(-)
>
>diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
>index 5257fe64b2..dbf08d681b 100644
>--- a/src/qemu/qemu_capabilities.c
>+++ b/src/qemu/qemu_capabilities.c
>@@ -3597,11 +3597,11 @@ virQEMUCapsInitHostCPUModel(virQEMUCaps *qemuCaps,
>                             virArch hostArch,
>                             virDomainVirtType type)
> {
>-    virCPUDef *cpu = NULL;
>-    virCPUDef *cpuExpanded = NULL;
>-    virCPUDef *migCPU = NULL;
>-    virCPUDef *hostCPU = NULL;
>-    virCPUDef *fullCPU = NULL;
>+    g_autoptr(virCPUDef) cpu = NULL;
>+    g_autoptr(virCPUDef) cpuExpanded = NULL;
>+    g_autoptr(virCPUDef) migCPU = NULL;

migCPU is also freed manually if virQEMUCapsInitCPUModel fails.
However in both callers of virQEMUCapsInitCPUModel the cpu argument is
allocated right above by virQEMUCapsNewHostCPUModel().

By moving the allocation inside virQEMUCapsInitCPUModel, the
virCPUDefFree can be removed.

Jano

>+    g_autoptr(virCPUDef) hostCPU = NULL;
>+    g_autoptr(virCPUDef) fullCPU = NULL;
>     size_t i;
>     int rc;
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20211118/75f52556/attachment-0001.sig>


More information about the libvir-list mailing list