* [PATCH for-9.2] hw/arm/sbsa-ref: Don't leak string in sbsa_fdt_add_gic_node()
@ 2024-08-22 16:23 Peter Maydell
2024-08-23 6:28 ` Philippe Mathieu-Daudé
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Peter Maydell @ 2024-08-22 16:23 UTC (permalink / raw)
To: qemu-arm, qemu-devel
Cc: Radoslaw Biernacki, Leif Lindholm, Marcin Juszkiewicz
In sbsa_fdt_add_gic_node() we g_strdup_printf() two nodename
strings, but only free one.
Since the string is actually entirely constant and we don't
make any use of printf's format-string operations, we can
drop the g_strdup_printf() use entirely.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
A small once-only leak, so this is 9.2 material. Spotted
with clang leak-sanitizer.
hw/arm/sbsa-ref.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
index ae37a923015..5cd8cd705be 100644
--- a/hw/arm/sbsa-ref.c
+++ b/hw/arm/sbsa-ref.c
@@ -164,23 +164,20 @@ static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
static void sbsa_fdt_add_gic_node(SBSAMachineState *sms)
{
- char *nodename;
+ const char *intc_nodename = "/intc";
+ const char *its_nodename = "/intc/its";
- 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_nodename);
+ qemu_fdt_setprop_sized_cells(sms->fdt, intc_nodename, "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, its_nodename);
+ qemu_fdt_setprop_sized_cells(sms->fdt, its_nodename, "reg",
2, sbsa_ref_memmap[SBSA_GIC_ITS].base,
2, sbsa_ref_memmap[SBSA_GIC_ITS].size);
-
- g_free(nodename);
}
/*
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH for-9.2] hw/arm/sbsa-ref: Don't leak string in sbsa_fdt_add_gic_node()
2024-08-22 16:23 [PATCH for-9.2] hw/arm/sbsa-ref: Don't leak string in sbsa_fdt_add_gic_node() Peter Maydell
@ 2024-08-23 6:28 ` Philippe Mathieu-Daudé
2024-08-23 6:42 ` Philippe Mathieu-Daudé
2024-08-27 4:38 ` Gavin Shan
2 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-08-23 6:28 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Radoslaw Biernacki, Leif Lindholm, Marcin Juszkiewicz
On 22/8/24 18:23, Peter Maydell wrote:
> In sbsa_fdt_add_gic_node() we g_strdup_printf() two nodename
> strings, but only free one.
>
> Since the string is actually entirely constant and we don't
> make any use of printf's format-string operations, we can
> drop the g_strdup_printf() use entirely.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> A small once-only leak, so this is 9.2 material. Spotted
> with clang leak-sanitizer.
>
> hw/arm/sbsa-ref.c | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH for-9.2] hw/arm/sbsa-ref: Don't leak string in sbsa_fdt_add_gic_node()
2024-08-22 16:23 [PATCH for-9.2] hw/arm/sbsa-ref: Don't leak string in sbsa_fdt_add_gic_node() Peter Maydell
2024-08-23 6:28 ` Philippe Mathieu-Daudé
@ 2024-08-23 6:42 ` Philippe Mathieu-Daudé
2024-08-25 12:13 ` Richard Henderson
2024-08-27 4:38 ` Gavin Shan
2 siblings, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-08-23 6:42 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Radoslaw Biernacki, Leif Lindholm, Marcin Juszkiewicz
On 22/8/24 18:23, Peter Maydell wrote:
> In sbsa_fdt_add_gic_node() we g_strdup_printf() two nodename
> strings, but only free one.
>
> Since the string is actually entirely constant and we don't
> make any use of printf's format-string operations, we can
> drop the g_strdup_printf() use entirely.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> A small once-only leak, so this is 9.2 material. Spotted
> with clang leak-sanitizer.
>
> hw/arm/sbsa-ref.c | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
> index ae37a923015..5cd8cd705be 100644
> --- a/hw/arm/sbsa-ref.c
> +++ b/hw/arm/sbsa-ref.c
> @@ -164,23 +164,20 @@ static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
>
> static void sbsa_fdt_add_gic_node(SBSAMachineState *sms)
> {
> - char *nodename;
> + const char *intc_nodename = "/intc";
> + const char *its_nodename = "/intc/its";
Should we use static qualifiers?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH for-9.2] hw/arm/sbsa-ref: Don't leak string in sbsa_fdt_add_gic_node()
2024-08-23 6:42 ` Philippe Mathieu-Daudé
@ 2024-08-25 12:13 ` Richard Henderson
0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2024-08-25 12:13 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, Peter Maydell, qemu-arm, qemu-devel
Cc: Radoslaw Biernacki, Leif Lindholm, Marcin Juszkiewicz
On 8/23/24 16:42, Philippe Mathieu-Daudé wrote:
>> static void sbsa_fdt_add_gic_node(SBSAMachineState *sms)
>> {
>> - char *nodename;
>> + const char *intc_nodename = "/intc";
>> + const char *its_nodename = "/intc/its";
>
> Should we use static qualifiers?'
No. The real object is the string literal. The local variable simply allows multiple
references within the function.
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH for-9.2] hw/arm/sbsa-ref: Don't leak string in sbsa_fdt_add_gic_node()
2024-08-22 16:23 [PATCH for-9.2] hw/arm/sbsa-ref: Don't leak string in sbsa_fdt_add_gic_node() Peter Maydell
2024-08-23 6:28 ` Philippe Mathieu-Daudé
2024-08-23 6:42 ` Philippe Mathieu-Daudé
@ 2024-08-27 4:38 ` Gavin Shan
2 siblings, 0 replies; 5+ messages in thread
From: Gavin Shan @ 2024-08-27 4:38 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Radoslaw Biernacki, Leif Lindholm, Marcin Juszkiewicz
On 8/23/24 2:23 AM, Peter Maydell wrote:
> In sbsa_fdt_add_gic_node() we g_strdup_printf() two nodename
> strings, but only free one.
>
> Since the string is actually entirely constant and we don't
> make any use of printf's format-string operations, we can
> drop the g_strdup_printf() use entirely.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> A small once-only leak, so this is 9.2 material. Spotted
> with clang leak-sanitizer.
>
> hw/arm/sbsa-ref.c | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
>
Reviewed-by: Gavin Shan <gshan@redhat.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-08-27 4:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-22 16:23 [PATCH for-9.2] hw/arm/sbsa-ref: Don't leak string in sbsa_fdt_add_gic_node() Peter Maydell
2024-08-23 6:28 ` Philippe Mathieu-Daudé
2024-08-23 6:42 ` Philippe Mathieu-Daudé
2024-08-25 12:13 ` Richard Henderson
2024-08-27 4:38 ` Gavin Shan
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).