[PATCH 07/31] virQEMUCapsInitGuest: Refactor cleanup and remove return value

Ján Tomko jtomko at redhat.com
Thu Mar 30 15:04:58 UTC 2023


On a Thursday in 2023, Peter Krempa wrote:
>Use automatic pointer freeing, remove 'ret' variable and also remove
>return value completely.
>
>Signed-off-by: Peter Krempa <pkrempa at redhat.com>
>---
> src/qemu/qemu_capabilities.c | 19 ++++---------------
> 1 file changed, 4 insertions(+), 15 deletions(-)
>
>diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
>index 72105a65a3..93915a9284 100644
>--- a/src/qemu/qemu_capabilities.c
>+++ b/src/qemu/qemu_capabilities.c
>@@ -984,15 +984,14 @@ virQEMUCapsGetDefaultEmulator(virArch hostarch,
> }
>
>
>-static int
>+static void
> virQEMUCapsInitGuest(virCaps *caps,
>                      virFileCache *cache,
>                      virArch hostarch,
>                      virArch guestarch)
> {
>-    char *binary = NULL;
>-    virQEMUCaps *qemuCaps = NULL;
>-    int ret = -1;
>+    g_autofree char *binary = NULL;
>+    g_autoptr(virQEMUCaps) qemuCaps = NULL;
>
>     binary = virQEMUCapsGetDefaultEmulator(hostarch, guestarch);
>
>@@ -1000,17 +999,10 @@ virQEMUCapsInitGuest(virCaps *caps,
>     if (binary) {
>         if (!(qemuCaps = virQEMUCapsCacheLookup(cache, binary))) {
>             virResetLastError();
>-            VIR_FREE(binary);

A 'return;' might be needed here.

Before, VIR_FREE would set 'binary' to NULL, making the following
virQEMUCapsInitGuestFromBinary call exit early.

Jano

>         }
>     }
>
>     virQEMUCapsInitGuestFromBinary(caps, binary, qemuCaps, guestarch);
>-    ret = 0;
>-
>-    VIR_FREE(binary);
>-    virObjectUnref(qemuCaps);
>-
>-    return ret;
> }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20230330/c3569caa/attachment.sig>


More information about the libvir-list mailing list