[PATCH v5 17/23] tools/bootconfig: fix fd leak in load_xbc_file() on fstat failure
From: Josh Law
Date: Sat Mar 14 2026 - 19:32:20 EST
If fstat() fails after open() succeeds, load_xbc_file() returns
-errno without closing the file descriptor. Add the missing close()
call on the error path.
Signed-off-by: Josh Law <objecting@xxxxxxxxxxxxx>
---
tools/bootconfig/main.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 55d59ed507d5..8078fee0b75b 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -162,8 +162,10 @@ static int load_xbc_file(const char *path, char **buf)
if (fd < 0)
return -errno;
ret = fstat(fd, &stat);
- if (ret < 0)
+ if (ret < 0) {
+ close(fd);
return -errno;
+ }
ret = load_xbc_fd(fd, buf, stat.st_size);
--
2.34.1