diff mbox series

hw/arm: fix memleak in sbsa-ref.c

Message ID 20240826141655.152179-2-frolov@swemel.ru (mailing list archive)
State New, archived
Headers show
Series hw/arm: fix memleak in sbsa-ref.c | expand

Commit Message

Dmitry Frolov Aug. 26, 2024, 2:16 p.m. UTC
Memory, allocated by the first call of g_strdup_printf() is lost at
the second call.

Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
---
 hw/arm/sbsa-ref.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

Comments

Philippe Mathieu-Daudé Aug. 26, 2024, 3:37 p.m. UTC | #1
Hi Dmitry,

On 26/8/24 16:16, Dmitry Frolov wrote:
> Memory, allocated by the first call of g_strdup_printf() is lost at
> the second call.
> 
> Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
> ---
>   hw/arm/sbsa-ref.c | 14 ++++----------
>   1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
> index ae37a92301..10984fc339 100644
> --- a/hw/arm/sbsa-ref.c
> +++ b/hw/arm/sbsa-ref.c
> @@ -164,23 +164,17 @@ static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
>   
>   static void sbsa_fdt_add_gic_node(SBSAMachineState *sms)
>   {
> -    char *nodename;
> -
> -    nodename = g_strdup_printf("/intc");
> -    qemu_fdt_add_subnode(sms->fdt, nodename);
> -    qemu_fdt_setprop_sized_cells(sms->fdt, nodename, "reg",
> +    qemu_fdt_add_subnode(sms->fdt, "/intc");
> +    qemu_fdt_setprop_sized_cells(sms->fdt, "/intc", "reg",
>                                    2, sbsa_ref_memmap[SBSA_GIC_DIST].base,
>                                    2, sbsa_ref_memmap[SBSA_GIC_DIST].size,
>                                    2, sbsa_ref_memmap[SBSA_GIC_REDIST].base,
>                                    2, sbsa_ref_memmap[SBSA_GIC_REDIST].size);
>   
> -    nodename = g_strdup_printf("/intc/its");
> -    qemu_fdt_add_subnode(sms->fdt, nodename);
> -    qemu_fdt_setprop_sized_cells(sms->fdt, nodename, "reg",
> +    qemu_fdt_add_subnode(sms->fdt, "/intc/its");
> +    qemu_fdt_setprop_sized_cells(sms->fdt, "/intc/its", "reg",
>                                    2, sbsa_ref_memmap[SBSA_GIC_ITS].base,
>                                    2, sbsa_ref_memmap[SBSA_GIC_ITS].size);
> -
> -    g_free(nodename);

Thanks for your patch, but Peter posted a similar one last week:
https://lore.kernel.org/qemu-devel/20240822162323.706382-1-peter.maydell@linaro.org/

>   }
>   
>   /*
diff mbox series

Patch

diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
index ae37a92301..10984fc339 100644
--- a/hw/arm/sbsa-ref.c
+++ b/hw/arm/sbsa-ref.c
@@ -164,23 +164,17 @@  static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
 
 static void sbsa_fdt_add_gic_node(SBSAMachineState *sms)
 {
-    char *nodename;
-
-    nodename = g_strdup_printf("/intc");
-    qemu_fdt_add_subnode(sms->fdt, nodename);
-    qemu_fdt_setprop_sized_cells(sms->fdt, nodename, "reg",
+    qemu_fdt_add_subnode(sms->fdt, "/intc");
+    qemu_fdt_setprop_sized_cells(sms->fdt, "/intc", "reg",
                                  2, sbsa_ref_memmap[SBSA_GIC_DIST].base,
                                  2, sbsa_ref_memmap[SBSA_GIC_DIST].size,
                                  2, sbsa_ref_memmap[SBSA_GIC_REDIST].base,
                                  2, sbsa_ref_memmap[SBSA_GIC_REDIST].size);
 
-    nodename = g_strdup_printf("/intc/its");
-    qemu_fdt_add_subnode(sms->fdt, nodename);
-    qemu_fdt_setprop_sized_cells(sms->fdt, nodename, "reg",
+    qemu_fdt_add_subnode(sms->fdt, "/intc/its");
+    qemu_fdt_setprop_sized_cells(sms->fdt, "/intc/its", "reg",
                                  2, sbsa_ref_memmap[SBSA_GIC_ITS].base,
                                  2, sbsa_ref_memmap[SBSA_GIC_ITS].size);
-
-    g_free(nodename);
 }
 
 /*