[libvirt PATCH] qemu: DomainGetGuestVcpusParams: reduce scope of tmp

Ján Tomko posted 1 patch 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/3ae7b5f7f5c692f32e1f5891e9abffe7cd582a69.1695995320.git.jtomko@redhat.com
src/qemu/qemu_driver.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
[libvirt PATCH] qemu: DomainGetGuestVcpusParams: reduce scope of tmp
Posted by Ján Tomko 7 months ago
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 <jtomko@redhat.com>
---
 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(&par, &npar, &maxpar, #name, tmp) < 0) \
-        goto cleanup; \
-    VIR_FREE(tmp)
+    do { \
+        g_autofree char *tmp = NULL; \
+        if (!(tmp = virBitmapFormat(name))) \
+            goto cleanup; \
+        if (virTypedParamsAddString(&par, &npar, &maxpar, #name, tmp) < 0) \
+            goto cleanup; \
+    } while (0)
 
     ADD_BITMAP(vcpus);
     ADD_BITMAP(online);
-- 
2.41.0

Re: [libvirt PATCH] qemu: DomainGetGuestVcpusParams: reduce scope of tmp
Posted by Jonathon Jongsma 7 months ago
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 <jtomko@redhat.com>
> ---
>   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(&par, &npar, &maxpar, #name, tmp) < 0) \
> -        goto cleanup; \
> -    VIR_FREE(tmp)
> +    do { \
> +        g_autofree char *tmp = NULL; \
> +        if (!(tmp = virBitmapFormat(name))) \
> +            goto cleanup; \
> +        if (virTypedParamsAddString(&par, &npar, &maxpar, #name, tmp) < 0) \
> +            goto cleanup; \
> +    } while (0)
>   
>       ADD_BITMAP(vcpus);
>       ADD_BITMAP(online);


Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>