[PATCH 2/2] nubus-device: ensure that name is freed after use in nubus_device_realize()

Mark Cave-Ayland posted 2 patches 4 years, 4 months ago
Maintainers: Laurent Vivier <laurent@vivier.eu>
[PATCH 2/2] nubus-device: ensure that name is freed after use in nubus_device_realize()
Posted by Mark Cave-Ayland 4 years, 4 months ago
Coverity points out that there is memory leak because name is never freed after
use in nubus_device_realize().

Fixes: Coverity CID 1464062
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-device.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
index 0f1852f671..64f837e44d 100644
--- a/hw/nubus/nubus-device.c
+++ b/hw/nubus/nubus-device.c
@@ -78,6 +78,7 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
         name = g_strdup_printf("nubus-slot-%x-declaration-rom", nd->slot);
         memory_region_init_rom(&nd->decl_rom, OBJECT(dev), name, size,
                                &error_abort);
+        g_free(name);
         ret = load_image_mr(path, &nd->decl_rom);
         g_free(path);
         if (ret < 0) {
-- 
2.20.1


Re: [PATCH 2/2] nubus-device: ensure that name is freed after use in nubus_device_realize()
Posted by Philippe Mathieu-Daudé 4 years, 4 months ago
On 10/2/21 14:31, Mark Cave-Ayland wrote:
> Coverity points out that there is memory leak because name is never freed after
> use in nubus_device_realize().
> 
> Fixes: Coverity CID 1464062
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/nubus-device.c | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Re: [PATCH 2/2] nubus-device: ensure that name is freed after use in nubus_device_realize()
Posted by Laurent Vivier 4 years, 4 months ago
Le 02/10/2021 à 14:31, Mark Cave-Ayland a écrit :
> Coverity points out that there is memory leak because name is never freed after
> use in nubus_device_realize().
> 
> Fixes: Coverity CID 1464062
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/nubus-device.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
> index 0f1852f671..64f837e44d 100644
> --- a/hw/nubus/nubus-device.c
> +++ b/hw/nubus/nubus-device.c
> @@ -78,6 +78,7 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
>          name = g_strdup_printf("nubus-slot-%x-declaration-rom", nd->slot);
>          memory_region_init_rom(&nd->decl_rom, OBJECT(dev), name, size,
>                                 &error_abort);
> +        g_free(name);
>          ret = load_image_mr(path, &nd->decl_rom);
>          g_free(path);
>          if (ret < 0) {
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>