[BlueZ v2 16/20] iso-tester: Fix fd leak

Bastien Nocera
2024-05-10T12:14:14Z

Error: RESOURCE_LEAK (CWE-772): [#def63] [important]
bluez-5.75/tools/iso-tester.c:1796:2: open_fn: Returning handle opened by "socket".
bluez-5.75/tools/iso-tester.c:1796:2: var_assign: Assigning: "sk" = handle returned from "socket(31, 2053, 8)".
bluez-5.75/tools/iso-tester.c:1807:3: leaked_handle: Handle variable "sk" going out of scope leaks the handle.
1805| if (!master_bdaddr) {
1806| tester_warn("No master bdaddr");
1807|-> return -ENODEV;
1808| }
1809|
---
tools/iso-tester.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/iso-tester.c b/tools/iso-tester.c
index 046606068206..d54fa56ecd44 100644
--- a/tools/iso-tester.c
+++ b/tools/iso-tester.c
@@ -1804,6 +1804,7 @@ static int create_iso_sock(struct test_data *data)
master_bdaddr = hciemu_get_central_bdaddr(data->hciemu);
if (!master_bdaddr) {
tester_warn("No master bdaddr");
+ close(sk);
return -ENODEV;
}

--
2.44.0