Re: [libvirt PATCH] qemu: DomainGetGuestVcpusParams: reduce scope of tmp
On 9/29/23 8:48 AM, Ján Tomko wrote: Wrap the macro body in a new block and move the declaration of 'tmp' into it, to avoid the need to mix g_autofree with manual freeing. Signed-off-by: Ján Tomko --- src/qemu/qemu_driver.c | 13 +++-- 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 056b5cec98..f3c9730cd8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18396,7 +18396,6 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPtr *params, 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; @@ -18416,11 +18415,13 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPtr *params, } #define ADD_BITMAP(name) \ -if (!(tmp = virBitmapFormat(name))) \ -goto cleanup; \ -if (virTypedParamsAddString(, , , #name, tmp) < 0) \ -goto cleanup; \ -VIR_FREE(tmp) +do { \ +g_autofree char *tmp = NULL; \ +if (!(tmp = virBitmapFormat(name))) \ +goto cleanup; \ +if (virTypedParamsAddString(, , , #name, tmp) < 0) \ +goto cleanup; \ +} while (0) ADD_BITMAP(vcpus); ADD_BITMAP(online); Reviewed-by: Jonathon Jongsma
[libvirt PATCH] qemu: DomainGetGuestVcpusParams: reduce scope of tmp
Wrap the macro body in a new block and move the declaration of 'tmp' into it, to avoid the need to mix g_autofree with manual freeing. Signed-off-by: Ján Tomko --- src/qemu/qemu_driver.c | 13 +++-- 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 056b5cec98..f3c9730cd8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18396,7 +18396,6 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPtr *params, 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; @@ -18416,11 +18415,13 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPtr *params, } #define ADD_BITMAP(name) \ -if (!(tmp = virBitmapFormat(name))) \ -goto cleanup; \ -if (virTypedParamsAddString(, , , #name, tmp) < 0) \ -goto cleanup; \ -VIR_FREE(tmp) +do { \ +g_autofree char *tmp = NULL; \ +if (!(tmp = virBitmapFormat(name))) \ +goto cleanup; \ +if (virTypedParamsAddString(, , , #name, tmp) < 0) \ +goto cleanup; \ +} while (0) ADD_BITMAP(vcpus); ADD_BITMAP(online); -- 2.41.0