[PATCH-for-5.2] 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/20201028192219.833329-1-f4bug@amsat.org
There is a newer version of this series
hw/rx/rx-gdbsim.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH-for-5.2] 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)
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
Peter mentioned this issue almost 2 months ago:
https://www.mail-archive.com/qemu-devel@nongnu.org/msg737946.html

Having helped Yoshinori to get his code merged, I feel the
reponsibility of fixing this before the release. I know I am
wrong, but since he is not responding to the review comments
and we are in soft-freeze, I prefer to do the dirty laundry
before we release.
---
 hw/rx/rx-gdbsim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/rx/rx-gdbsim.c b/hw/rx/rx-gdbsim.c
index 417ec0564b3..67c413f9de2 100644
--- a/hw/rx/rx-gdbsim.c
+++ b/hw/rx/rx-gdbsim.c
@@ -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;
 
             dtb = load_device_tree(dtb_filename, &dtb_size);
             if (dtb == NULL) {
-- 
2.26.2

Re: [PATCH-for-5.2] hw/rx/rx-gdbsim: Fix memory leak
Posted by Richard Henderson 3 years, 6 months ago
On 10/28/20 12:22 PM, Philippe Mathieu-Daudé wrote:
> +            g_autofree void *dtb;
>  
>              dtb = load_device_tree(dtb_filename, &dtb_size);

With g_autofree, we must initialize the variable on declaration.  Often this is
with NULL, but in this case, just merge these two lines.

With that,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

Re: [PATCH-for-5.2] hw/rx/rx-gdbsim: Fix memory leak
Posted by Philippe Mathieu-Daudé 3 years, 6 months ago
On 10/29/20 8:57 PM, Richard Henderson wrote:
> On 10/28/20 12:22 PM, Philippe Mathieu-Daudé wrote:
>> +            g_autofree void *dtb;
>>  
>>              dtb = load_device_tree(dtb_filename, &dtb_size);
> 
> With g_autofree, we must initialize the variable on declaration.  Often this is
> with NULL, but in this case, just merge these two lines.

OK.

> 
> With that,
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Thanks!