util: fix possible fd leak if xconnect fails on connect()

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
This commit is contained in:
Peter Hutterer 2026-05-11 11:42:12 +10:00 committed by Marge Bot
parent 1efc6d03d1
commit f12fe4ce14

View file

@ -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);
}
/**