qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v1 1/1] riscv: spike: Fix memory leak in the board init
@ 2018-11-05 19:44 Alistair Francis
  2018-11-06 13:25 ` Peter Maydell
  2018-11-06 23:58 ` Palmer Dabbelt
  0 siblings, 2 replies; 3+ messages in thread
From: Alistair Francis @ 2018-11-05 19:44 UTC (permalink / raw)
  To: qemu-devel, qemu-riscv; +Cc: Alistair Francis, alistair23, peter.maydell

Coverity caught a malloc() call that was never freed. This patch ensures
that we free the memory but also updates the allocation to use
g_strdup_printf() instead of malloc().

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/riscv/spike.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c
index 8a712ed490..268df04c3c 100644
--- a/hw/riscv/spike.c
+++ b/hw/riscv/spike.c
@@ -316,9 +316,7 @@ static void spike_v1_09_1_board_init(MachineState *machine)
 
     /* build config string with supplied memory size */
     char *isa = riscv_isa_string(&s->soc.harts[0]);
-    size_t config_string_size = strlen(config_string_tmpl) + 48;
-    char *config_string = malloc(config_string_size);
-    snprintf(config_string, config_string_size, config_string_tmpl,
+    char *config_string = g_strdup_printf(config_string_tmpl,
         (uint64_t)memmap[SPIKE_CLINT].base + SIFIVE_TIME_BASE,
         (uint64_t)memmap[SPIKE_DRAM].base,
         (uint64_t)ram_size, isa,
@@ -345,6 +343,8 @@ static void spike_v1_09_1_board_init(MachineState *machine)
     /* Core Local Interruptor (timer and IPI) */
     sifive_clint_create(memmap[SPIKE_CLINT].base, memmap[SPIKE_CLINT].size,
         smp_cpus, SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE);
+
+    g_free(config_string);
 }
 
 static void spike_v1_09_1_machine_init(MachineClass *mc)
-- 
2.19.1

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

* Re: [Qemu-devel] [PATCH v1 1/1] riscv: spike: Fix memory leak in the board init
  2018-11-05 19:44 [Qemu-devel] [PATCH v1 1/1] riscv: spike: Fix memory leak in the board init Alistair Francis
@ 2018-11-06 13:25 ` Peter Maydell
  2018-11-06 23:58 ` Palmer Dabbelt
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2018-11-06 13:25 UTC (permalink / raw)
  To: Alistair Francis; +Cc: qemu-devel, qemu-riscv, alistair23

On 5 November 2018 at 19:44, Alistair Francis <Alistair.Francis@wdc.com> wrote:
> Coverity caught a malloc() call that was never freed. This patch ensures
> that we free the memory but also updates the allocation to use
> g_strdup_printf() instead of malloc().
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM

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

* Re: [Qemu-devel] [PATCH v1 1/1] riscv: spike: Fix memory leak in the board init
  2018-11-05 19:44 [Qemu-devel] [PATCH v1 1/1] riscv: spike: Fix memory leak in the board init Alistair Francis
  2018-11-06 13:25 ` Peter Maydell
@ 2018-11-06 23:58 ` Palmer Dabbelt
  1 sibling, 0 replies; 3+ messages in thread
From: Palmer Dabbelt @ 2018-11-06 23:58 UTC (permalink / raw)
  Cc: qemu-devel, qemu-riscv, alistair23, Alistair Francis, Peter Maydell

On Mon, 05 Nov 2018 11:44:41 PST (-0800), Alistair Francis wrote:
> Coverity caught a malloc() call that was never freed. This patch ensures
> that we free the memory but also updates the allocation to use
> g_strdup_printf() instead of malloc().
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  hw/riscv/spike.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c
> index 8a712ed490..268df04c3c 100644
> --- a/hw/riscv/spike.c
> +++ b/hw/riscv/spike.c
> @@ -316,9 +316,7 @@ static void spike_v1_09_1_board_init(MachineState *machine)
>  
>      /* build config string with supplied memory size */
>      char *isa = riscv_isa_string(&s->soc.harts[0]);
> -    size_t config_string_size = strlen(config_string_tmpl) + 48;
> -    char *config_string = malloc(config_string_size);
> -    snprintf(config_string, config_string_size, config_string_tmpl,
> +    char *config_string = g_strdup_printf(config_string_tmpl,
>          (uint64_t)memmap[SPIKE_CLINT].base + SIFIVE_TIME_BASE,
>          (uint64_t)memmap[SPIKE_DRAM].base,
>          (uint64_t)ram_size, isa,
> @@ -345,6 +343,8 @@ static void spike_v1_09_1_board_init(MachineState *machine)
>      /* Core Local Interruptor (timer and IPI) */
>      sifive_clint_create(memmap[SPIKE_CLINT].base, memmap[SPIKE_CLINT].size,
>          smp_cpus, SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE);
> +
> +    g_free(config_string);
>  }
>  
>  static void spike_v1_09_1_machine_init(MachineClass *mc)

Reviewed-by: Palmer Dabbelt <palmer@sifive.com>

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

end of thread, other threads:[~2018-11-06 23:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-05 19:44 [Qemu-devel] [PATCH v1 1/1] riscv: spike: Fix memory leak in the board init Alistair Francis
2018-11-06 13:25 ` Peter Maydell
2018-11-06 23:58 ` Palmer Dabbelt

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).