[PATCH-for-5.2 v3] hw/rx/rx-gdbsim: Fix memory leak

Philippe Mathieu-Daudé posted 1 patch 3 years, 6 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20201102104542.2064745-1-f4bug@amsat.org
hw/rx/rx-gdbsim.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH-for-5.2 v3] hw/rx/rx-gdbsim: Fix memory leak
Posted by Philippe Mathieu-Daudé 3 years, 6 months ago
As load_device_tree() returns allocated memory,
we need to free it.

Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Fixes: bda19d7bb56 ("hw/rx: Add RX GDB simulator")
Reported-by: Coverity (CID 1432307: RESOURCE_LEAK)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
v3: Directly initialize the variable on declaration (Richard)
---
 hw/rx/rx-gdbsim.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/rx/rx-gdbsim.c b/hw/rx/rx-gdbsim.c
index 417ec0564b3..285549c79b5 100644
--- a/hw/rx/rx-gdbsim.c
+++ b/hw/rx/rx-gdbsim.c
@@ -122,9 +122,8 @@ static void rx_gdbsim_init(MachineState *machine)
         if (dtb_filename) {
             ram_addr_t dtb_offset;
             int dtb_size;
-            void *dtb;
+            g_autofree void *dtb = load_device_tree(dtb_filename, &dtb_size);
 
-            dtb = load_device_tree(dtb_filename, &dtb_size);
             if (dtb == NULL) {
                 error_report("Couldn't open dtb file %s", dtb_filename);
                 exit(1);
-- 
2.26.2

Re: [PATCH-for-5.2 v3] hw/rx/rx-gdbsim: Fix memory leak
Posted by Philippe Mathieu-Daudé 3 years, 5 months ago
On 11/2/20 11:45 AM, Philippe Mathieu-Daudé wrote:
> As load_device_tree() returns allocated memory,
> we need to free it.
> 
> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> Fixes: bda19d7bb56 ("hw/rx: Add RX GDB simulator")
> Reported-by: Coverity (CID 1432307: RESOURCE_LEAK)
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> v3: Directly initialize the variable on declaration (Richard)
> ---
>  hw/rx/rx-gdbsim.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)

Thanks, applied to renesas-fixes.