[PATCH 3/4] hw/arm/aspeed_gpio: Don't leak string in aspeed_gpio_init()

Peter Maydell posted 4 patches 2 days, 18 hours ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Thomas Huth <thuth@redhat.com>, "Cédric Le Goater" <clg@kaod.org>, Peter Maydell <peter.maydell@linaro.org>, Steven Lee <steven_lee@aspeedtech.com>, Troy Lee <leetroy@gmail.com>, Jamin Lin <jamin_lin@aspeedtech.com>, Andrew Jeffery <andrew@codeconstruct.com.au>, Joel Stanley <joel@jms.id.au>, Eric Auger <eric.auger@redhat.com>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
[PATCH 3/4] hw/arm/aspeed_gpio: Don't leak string in aspeed_gpio_init()
Posted by Peter Maydell 2 days, 18 hours ago
We allocate the string for the GPIO property name, but never free it.
Use g_autofree to avoid this.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/gpio/aspeed_gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/gpio/aspeed_gpio.c b/hw/gpio/aspeed_gpio.c
index d9237d4360..7d0f87e90c 100644
--- a/hw/gpio/aspeed_gpio.c
+++ b/hw/gpio/aspeed_gpio.c
@@ -1488,7 +1488,7 @@ static void aspeed_gpio_init(Object *obj)
     }
 
     for (int i = 0; i < agc->nr_gpio_sets; i++) {
-        char *name = g_strdup_printf("gpio-set[%d]", i);
+        g_autofree char *name = g_strdup_printf("gpio-set[%d]", i);
         object_property_add(obj, name, "uint32", aspeed_gpio_get_set,
         aspeed_gpio_set_set, NULL, NULL);
     }
-- 
2.43.0
Re: [PATCH 3/4] hw/arm/aspeed_gpio: Don't leak string in aspeed_gpio_init()
Posted by Cédric Le Goater 2 days, 2 hours ago
On 2/27/26 14:57, Peter Maydell wrote:
> We allocate the string for the GPIO property name, but never free it.
> Use g_autofree to avoid this.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   hw/gpio/aspeed_gpio.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/gpio/aspeed_gpio.c b/hw/gpio/aspeed_gpio.c
> index d9237d4360..7d0f87e90c 100644
> --- a/hw/gpio/aspeed_gpio.c
> +++ b/hw/gpio/aspeed_gpio.c
> @@ -1488,7 +1488,7 @@ static void aspeed_gpio_init(Object *obj)
>       }
>   
>       for (int i = 0; i < agc->nr_gpio_sets; i++) {
> -        char *name = g_strdup_printf("gpio-set[%d]", i);
> +        g_autofree char *name = g_strdup_printf("gpio-set[%d]", i);
>           object_property_add(obj, name, "uint32", aspeed_gpio_get_set,
>           aspeed_gpio_set_set, NULL, NULL);
>       }

Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.

Re: [PATCH 3/4] hw/arm/aspeed_gpio: Don't leak string in aspeed_gpio_init()
Posted by Philippe Mathieu-Daudé 2 days, 10 hours ago
On 27/2/26 14:57, Peter Maydell wrote:
> We allocate the string for the GPIO property name, but never free it.
> Use g_autofree to avoid this.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   hw/gpio/aspeed_gpio.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>