qemu-riscv
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 1/1] riscv/boot: Fix possible memory leak


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v1 1/1] riscv/boot: Fix possible memory leak
Date: Thu, 3 Oct 2019 09:04:51 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0

On 10/2/19 11:34 PM, Alistair Francis wrote:
Coverity (CID 1405786) thinks that there is a possible memory leak as
we don't guarentee that the memory allocatd from riscv_find_firmware()

typos: 'guarantee', 'allocated'

is freed. This is a false positive, but let's tidy up the code to fix
the warning.

Signed-off-by: Alistair Francis <address@hidden>
---
  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);


Reviewed-by: Philippe Mathieu-Daudé <address@hidden>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]