Skip to contentSkip to conversation

hw/rx/rx-gdbsim: Fix memory leak

PATCH Superseded Philippe Mathieu-Daudé 2 participants 2 messages Oct 30, 2020

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hw/rx/rx-gdbsim: Fix memory leak

As load_device_tree() returns allocated memory, we need to free it.

Cc Yoshinori Sato <[email protected]>
Fixes bda19d7bb56 ("hw/rx: Add RX GDB simulator")
Reported-by Coverity (CID 1432307: RESOURCE_LEAK)

---
v2: NULL-initialize (Richard)

---
 hw/rx/rx-gdbsim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/rx/rx-gdbsim.c +1 -1
index 417ec0564b3..d70865962e8 100644
@@ -122,7 +122,7 @@ static void rx_gdbsim_init(MachineState *machine)
         if (dtb_filename) {
             ram_addr_t dtb_offset;
             int dtb_size;
-            void *dtb;
+            g_autofree void *dtb = NULL;
 
             dtb = load_device_tree(dtb_filename, &dtb_size);
             if (dtb == NULL) {
Signature · 1 line
2.26.2
#1 lore raw
Quoted 18 lines · Philippe Mathieu-Daudé

As load_device_tree() returns allocated memory, we need to free it.

Cc Yoshinori Sato <[email protected]>
Fixes bda19d7bb56 ("hw/rx: Add RX GDB simulator")
Reported-by Coverity (CID 1432307: RESOURCE_LEAK)

---
v2: NULL-initialize (Richard)

---
 hw/rx/rx-gdbsim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/rx/rx-gdbsim.c +0 -0
index 417ec0564b3..d70865962e8 100644

hw/rx/rx-gdbsim.c static void rx_gdbsim_init(MachineState *machine) · line 127

Quoted 7 lines
hw/rx/rx-gdbsim.c +1 -1
@@ -122,7 +122,7 @@ static void rx_gdbsim_init(MachineState *machine)
         if (dtb_filename) {
             ram_addr_t dtb_offset;
             int dtb_size;
-            void *dtb;
+            g_autofree void *dtb = NULL;
 
             dtb = load_device_tree(dtb_filename, &dtb_size);

What I said was, merge the declaration and statement:

  g_autofree void *dtb =
    load_device_tree(...);

but whatever. You can still keep my previous conditional r-b.

r~