diff mbox series

[BlueZ,10/15] test-runner: Fix fd leak on failure

Message ID 20240516090340.61417-11-hadess@hadess.net
State New
Headers show
Series Fix a number of static analysis issues #2 | expand

Commit Message

Bastien Nocera May 16, 2024, 9:03 a.m. UTC
Error: RESOURCE_LEAK (CWE-772): [#def65] [important]
bluez-5.75/tools/test-runner.c:877:3: open_fn: Returning handle opened by "attach_proto".
bluez-5.75/tools/test-runner.c:877:3: var_assign: Assigning: "serial_fd" = handle returned from "attach_proto(node, 0U, basic_flags, extra_flags)".
bluez-5.75/tools/test-runner.c:955:3: leaked_handle: Handle variable "serial_fd" going out of scope leaks the handle.
953|	if (pid < 0) {
954|		perror("Failed to fork new process");
955|->		return;
956|	}
957|
---
 tools/test-runner.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/tools/test-runner.c b/tools/test-runner.c
index 908327255ad7..de0f2260480c 100644
--- a/tools/test-runner.c
+++ b/tools/test-runner.c
@@ -952,6 +952,8 @@  start_next:
 	pid = fork();
 	if (pid < 0) {
 		perror("Failed to fork new process");
+		if (serial_fd >= 0)
+			close(serial_fd);
 		return;
 	}