* [PATCH v2 1/1] riscv/boot: Fix possible memory leak
@ 2019-10-03 16:59 ` Alistair Francis
0 siblings, 0 replies; 6+ messages in thread
From: Alistair Francis @ 2019-10-03 16:59 UTC (permalink / raw)
To: qemu-devel, qemu-riscv; +Cc: alistair23, palmer, alistair.francis
Coverity (CID 1405786) thinks that there is a possible memory leak as
we don't guarantee that the memory allocated from riscv_find_firmware()
is freed. This is a false positive, but let's tidy up the code to fix
the warning.
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v2:
- Fix commit typos
hw/riscv/boot.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index 2e92fb0680..7fee98d2f8 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -38,7 +38,7 @@ void riscv_find_and_load_firmware(MachineState *machine,
const char *default_machine_firmware,
hwaddr firmware_load_addr)
{
- char *firmware_filename;
+ char *firmware_filename = NULL;
if (!machine->firmware) {
/*
@@ -70,14 +70,11 @@ void riscv_find_and_load_firmware(MachineState *machine,
* if no -bios option is set without breaking anything.
*/
firmware_filename = riscv_find_firmware(default_machine_firmware);
- } else {
- firmware_filename = machine->firmware;
- if (strcmp(firmware_filename, "none")) {
- firmware_filename = riscv_find_firmware(firmware_filename);
- }
+ } else if (strcmp(machine->firmware, "none")) {
+ firmware_filename = riscv_find_firmware(machine->firmware);
}
- if (strcmp(firmware_filename, "none")) {
+ if (firmware_filename) {
/* If not "none" load the firmware */
riscv_load_firmware(firmware_filename, firmware_load_addr);
g_free(firmware_filename);
--
2.23.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 1/1] riscv/boot: Fix possible memory leak
@ 2019-10-03 16:59 ` Alistair Francis
0 siblings, 0 replies; 6+ messages in thread
From: Alistair Francis @ 2019-10-03 16:59 UTC (permalink / raw)
To: qemu-devel, qemu-riscv; +Cc: palmer, alistair.francis, alistair23
Coverity (CID 1405786) thinks that there is a possible memory leak as
we don't guarantee that the memory allocated from riscv_find_firmware()
is freed. This is a false positive, but let's tidy up the code to fix
the warning.
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v2:
- Fix commit typos
hw/riscv/boot.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index 2e92fb0680..7fee98d2f8 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -38,7 +38,7 @@ void riscv_find_and_load_firmware(MachineState *machine,
const char *default_machine_firmware,
hwaddr firmware_load_addr)
{
- char *firmware_filename;
+ char *firmware_filename = NULL;
if (!machine->firmware) {
/*
@@ -70,14 +70,11 @@ void riscv_find_and_load_firmware(MachineState *machine,
* if no -bios option is set without breaking anything.
*/
firmware_filename = riscv_find_firmware(default_machine_firmware);
- } else {
- firmware_filename = machine->firmware;
- if (strcmp(firmware_filename, "none")) {
- firmware_filename = riscv_find_firmware(firmware_filename);
- }
+ } else if (strcmp(machine->firmware, "none")) {
+ firmware_filename = riscv_find_firmware(machine->firmware);
}
- if (strcmp(firmware_filename, "none")) {
+ if (firmware_filename) {
/* If not "none" load the firmware */
riscv_load_firmware(firmware_filename, firmware_load_addr);
g_free(firmware_filename);
--
2.23.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/1] riscv/boot: Fix possible memory leak
2019-10-03 16:59 ` Alistair Francis
@ 2019-10-17 12:08 ` Peter Maydell
-1 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2019-10-17 12:08 UTC (permalink / raw)
To: Alistair Francis
Cc: Alistair Francis, Palmer Dabbelt, open list:RISC-V, QEMU Developers
Ping? It would be nice to see this patch get into master
to silence the coverity errors.
thanks
-- PMM
On Thu, 3 Oct 2019 at 18:05, Alistair Francis <alistair.francis@wdc.com> wrote:
>
> Coverity (CID 1405786) thinks that there is a possible memory leak as
> we don't guarantee that the memory allocated from riscv_find_firmware()
> is freed. This is a false positive, but let's tidy up the code to fix
> the warning.
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> v2:
> - Fix commit typos
>
> hw/riscv/boot.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
> index 2e92fb0680..7fee98d2f8 100644
> --- a/hw/riscv/boot.c
> +++ b/hw/riscv/boot.c
> @@ -38,7 +38,7 @@ void riscv_find_and_load_firmware(MachineState *machine,
> const char *default_machine_firmware,
> hwaddr firmware_load_addr)
> {
> - char *firmware_filename;
> + char *firmware_filename = NULL;
>
> if (!machine->firmware) {
> /*
> @@ -70,14 +70,11 @@ void riscv_find_and_load_firmware(MachineState *machine,
> * if no -bios option is set without breaking anything.
> */
> firmware_filename = riscv_find_firmware(default_machine_firmware);
> - } else {
> - firmware_filename = machine->firmware;
> - if (strcmp(firmware_filename, "none")) {
> - firmware_filename = riscv_find_firmware(firmware_filename);
> - }
> + } else if (strcmp(machine->firmware, "none")) {
> + firmware_filename = riscv_find_firmware(machine->firmware);
> }
>
> - if (strcmp(firmware_filename, "none")) {
> + if (firmware_filename) {
> /* If not "none" load the firmware */
> riscv_load_firmware(firmware_filename, firmware_load_addr);
> g_free(firmware_filename);
> --
> 2.23.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/1] riscv/boot: Fix possible memory leak
@ 2019-10-17 12:08 ` Peter Maydell
0 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2019-10-17 12:08 UTC (permalink / raw)
To: Alistair Francis
Cc: QEMU Developers, open list:RISC-V, Alistair Francis, Palmer Dabbelt
Ping? It would be nice to see this patch get into master
to silence the coverity errors.
thanks
-- PMM
On Thu, 3 Oct 2019 at 18:05, Alistair Francis <alistair.francis@wdc.com> wrote:
>
> Coverity (CID 1405786) thinks that there is a possible memory leak as
> we don't guarantee that the memory allocated from riscv_find_firmware()
> is freed. This is a false positive, but let's tidy up the code to fix
> the warning.
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> v2:
> - Fix commit typos
>
> hw/riscv/boot.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
> index 2e92fb0680..7fee98d2f8 100644
> --- a/hw/riscv/boot.c
> +++ b/hw/riscv/boot.c
> @@ -38,7 +38,7 @@ void riscv_find_and_load_firmware(MachineState *machine,
> const char *default_machine_firmware,
> hwaddr firmware_load_addr)
> {
> - char *firmware_filename;
> + char *firmware_filename = NULL;
>
> if (!machine->firmware) {
> /*
> @@ -70,14 +70,11 @@ void riscv_find_and_load_firmware(MachineState *machine,
> * if no -bios option is set without breaking anything.
> */
> firmware_filename = riscv_find_firmware(default_machine_firmware);
> - } else {
> - firmware_filename = machine->firmware;
> - if (strcmp(firmware_filename, "none")) {
> - firmware_filename = riscv_find_firmware(firmware_filename);
> - }
> + } else if (strcmp(machine->firmware, "none")) {
> + firmware_filename = riscv_find_firmware(machine->firmware);
> }
>
> - if (strcmp(firmware_filename, "none")) {
> + if (firmware_filename) {
> /* If not "none" load the firmware */
> riscv_load_firmware(firmware_filename, firmware_load_addr);
> g_free(firmware_filename);
> --
> 2.23.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/1] riscv/boot: Fix possible memory leak
2019-10-17 12:08 ` Peter Maydell
@ 2019-10-18 20:41 ` Palmer Dabbelt
-1 siblings, 0 replies; 6+ messages in thread
From: Palmer Dabbelt @ 2019-10-18 20:41 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-riscv, Alistair Francis, qemu-devel, alistair23
On Thu, 17 Oct 2019 05:08:39 PDT (-0700), Peter Maydell wrote:
> Ping? It would be nice to see this patch get into master
> to silence the coverity errors.
Sorry, it looks like I dropped this. It's in my queue, I hope to submit a PR
soon.
>
> thanks
> -- PMM
>
> On Thu, 3 Oct 2019 at 18:05, Alistair Francis <alistair.francis@wdc.com> wrote:
>>
>> Coverity (CID 1405786) thinks that there is a possible memory leak as
>> we don't guarantee that the memory allocated from riscv_find_firmware()
>> is freed. This is a false positive, but let's tidy up the code to fix
>> the warning.
>>
>> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
>> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>> v2:
>> - Fix commit typos
>>
>> hw/riscv/boot.c | 11 ++++-------
>> 1 file changed, 4 insertions(+), 7 deletions(-)
>>
>> diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
>> index 2e92fb0680..7fee98d2f8 100644
>> --- a/hw/riscv/boot.c
>> +++ b/hw/riscv/boot.c
>> @@ -38,7 +38,7 @@ void riscv_find_and_load_firmware(MachineState *machine,
>> const char *default_machine_firmware,
>> hwaddr firmware_load_addr)
>> {
>> - char *firmware_filename;
>> + char *firmware_filename = NULL;
>>
>> if (!machine->firmware) {
>> /*
>> @@ -70,14 +70,11 @@ void riscv_find_and_load_firmware(MachineState *machine,
>> * if no -bios option is set without breaking anything.
>> */
>> firmware_filename = riscv_find_firmware(default_machine_firmware);
>> - } else {
>> - firmware_filename = machine->firmware;
>> - if (strcmp(firmware_filename, "none")) {
>> - firmware_filename = riscv_find_firmware(firmware_filename);
>> - }
>> + } else if (strcmp(machine->firmware, "none")) {
>> + firmware_filename = riscv_find_firmware(machine->firmware);
>> }
>>
>> - if (strcmp(firmware_filename, "none")) {
>> + if (firmware_filename) {
>> /* If not "none" load the firmware */
>> riscv_load_firmware(firmware_filename, firmware_load_addr);
>> g_free(firmware_filename);
>> --
>> 2.23.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/1] riscv/boot: Fix possible memory leak
@ 2019-10-18 20:41 ` Palmer Dabbelt
0 siblings, 0 replies; 6+ messages in thread
From: Palmer Dabbelt @ 2019-10-18 20:41 UTC (permalink / raw)
To: Peter Maydell; +Cc: Alistair Francis, qemu-devel, qemu-riscv, alistair23
On Thu, 17 Oct 2019 05:08:39 PDT (-0700), Peter Maydell wrote:
> Ping? It would be nice to see this patch get into master
> to silence the coverity errors.
Sorry, it looks like I dropped this. It's in my queue, I hope to submit a PR
soon.
>
> thanks
> -- PMM
>
> On Thu, 3 Oct 2019 at 18:05, Alistair Francis <alistair.francis@wdc.com> wrote:
>>
>> Coverity (CID 1405786) thinks that there is a possible memory leak as
>> we don't guarantee that the memory allocated from riscv_find_firmware()
>> is freed. This is a false positive, but let's tidy up the code to fix
>> the warning.
>>
>> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
>> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>> v2:
>> - Fix commit typos
>>
>> hw/riscv/boot.c | 11 ++++-------
>> 1 file changed, 4 insertions(+), 7 deletions(-)
>>
>> diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
>> index 2e92fb0680..7fee98d2f8 100644
>> --- a/hw/riscv/boot.c
>> +++ b/hw/riscv/boot.c
>> @@ -38,7 +38,7 @@ void riscv_find_and_load_firmware(MachineState *machine,
>> const char *default_machine_firmware,
>> hwaddr firmware_load_addr)
>> {
>> - char *firmware_filename;
>> + char *firmware_filename = NULL;
>>
>> if (!machine->firmware) {
>> /*
>> @@ -70,14 +70,11 @@ void riscv_find_and_load_firmware(MachineState *machine,
>> * if no -bios option is set without breaking anything.
>> */
>> firmware_filename = riscv_find_firmware(default_machine_firmware);
>> - } else {
>> - firmware_filename = machine->firmware;
>> - if (strcmp(firmware_filename, "none")) {
>> - firmware_filename = riscv_find_firmware(firmware_filename);
>> - }
>> + } else if (strcmp(machine->firmware, "none")) {
>> + firmware_filename = riscv_find_firmware(machine->firmware);
>> }
>>
>> - if (strcmp(firmware_filename, "none")) {
>> + if (firmware_filename) {
>> /* If not "none" load the firmware */
>> riscv_load_firmware(firmware_filename, firmware_load_addr);
>> g_free(firmware_filename);
>> --
>> 2.23.0
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-10-18 20:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-03 16:59 [PATCH v2 1/1] riscv/boot: Fix possible memory leak Alistair Francis
2019-10-03 16:59 ` Alistair Francis
2019-10-17 12:08 ` Peter Maydell
2019-10-17 12:08 ` Peter Maydell
2019-10-18 20:41 ` Palmer Dabbelt
2019-10-18 20:41 ` Palmer Dabbelt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.