monitor: Fix memory leaks
authorGopal Tiwari <gtiwari@redhat.com>
Tue, 31 May 2022 07:41:07 +0000 (13:11 +0530)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
While performing static tool analysis using coverity
found following reports for resouse leak

bluez-5.64/monitor/jlink.c:111: leaked_storage: Variable "so"
going out of scope leaks the storage it points to.

bluez-5.64/monitor/jlink.c:113: leaked_storage: Variable "so"
going out of scope leaks the storage it points to.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
monitor/jlink.c

index 9aaa4eb..f1d8ce6 100644 (file)
@@ -107,9 +107,12 @@ int jlink_init(void)
                        !jlink.tif_select || !jlink.setspeed ||
                        !jlink.connect || !jlink.getsn ||
                        !jlink.emu_getproductname ||
-                       !jlink.rtterminal_control || !jlink.rtterminal_read)
+                       !jlink.rtterminal_control || !jlink.rtterminal_read) {
+               dlclose(so);
                return -EIO;
+       }
 
+       dlclose(so);
        return 0;
 }