riscv: spike: Fix memory leak in the board init
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> Reviewed-by: Palmer Dabbelt <palmer@sifive.com> Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
This commit is contained in:
parent
a7ce790a02
commit
00a014ac01
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user