From 566af9c2f5efaa33ebb093efb3a03f83876943ba Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 16 May 2024 11:03:14 +0200 Subject: [PATCH] test-runner: Fix fd leak on failure Error: RESOURCE_LEAK (CWE-772): [#def65] [important] tools/test-runner.c:877:3: open_fn: Returning handle opened by "attach_proto". tools/test-runner.c:877:3: var_assign: Assigning: "serial_fd" = handle returned from "attach_proto(node, 0U, basic_flags, extra_flags)". 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 --git a/tools/test-runner.c b/tools/test-runner.c index 908327255..de0f22604 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; } -- 2.47.3