qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/arm: fix memleak in sbsa-ref.c
@ 2024-08-26 14:16 Dmitry Frolov
  2024-08-26 15:37 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Frolov @ 2024-08-26 14:16 UTC (permalink / raw)
  To: rad, peter.maydell; +Cc: sdl.qemu, qemu-devel, Dmitry Frolov

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);
 }
 
 /*
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hw/arm: fix memleak in sbsa-ref.c
  2024-08-26 14:16 [PATCH] hw/arm: fix memleak in sbsa-ref.c Dmitry Frolov
@ 2024-08-26 15:37 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-08-26 15:37 UTC (permalink / raw)
  To: Dmitry Frolov, rad, peter.maydell; +Cc: sdl.qemu, qemu-devel

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/

>   }
>   
>   /*



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-26 15:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-26 14:16 [PATCH] hw/arm: fix memleak in sbsa-ref.c Dmitry Frolov
2024-08-26 15:37 ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).