hw/rx/rx-gdbsim: Fix memory leak (CID 1432307)
authorPhilippe Mathieu-Daudé <f4bug@amsat.org>
Wed, 28 Oct 2020 15:08:10 +0000 (16:08 +0100)
committerPhilippe Mathieu-Daudé <f4bug@amsat.org>
Sun, 8 Nov 2020 23:53:07 +0000 (00:53 +0100)
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>
Message-Id: <20201102104542.2064745-1-f4bug@amsat.org>

hw/rx/rx-gdbsim.c

index 417ec0564b3b1471545b5534c8f883c2c8e63ddd..285549c79b580d9fb89c11a66a8616668e14ed0f 100644 (file)
@@ -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);