From f12fe4ce14b07131a43f56d7edabe5b3fc829841 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 11 May 2026 11:42:12 +1000 Subject: [PATCH] util: fix possible fd leak if xconnect fails on connect() Assisted-by: Claude:claude-opus-4-6 Part-of: --- src/util-io.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util-io.h b/src/util-io.h index 21d5d81..0ea7d63 100644 --- a/src/util-io.h +++ b/src/util-io.h @@ -223,7 +223,8 @@ xconnect(const char *path) if (!xsnprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path)) return -EINVAL; - int sockfd = xerrno(SYSCALL(socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0))); + _cleanup_close_ int sockfd = + xerrno(SYSCALL(socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0))); if (sockfd < 0) return sockfd; @@ -231,7 +232,7 @@ xconnect(const char *path) if (rc < 0) return rc; - return sockfd; + return steal_fd(&sockfd); } /**