From: Marcin Ślusarz Date: Fri, 24 Jul 2020 15:51:25 +0000 (+0200) Subject: util: fix possible fd leaks in os_socket_listen_abstract X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=eac0ba7fc193cceccd953bc4726ceef750b18085;p=mesa.git util: fix possible fd leaks in os_socket_listen_abstract Found by Coverity. Signed-off-by: Marcin Ślusarz Fixes: ef5266ebd50 ("util/os_socket: Add socket related functions.") Reviewed-by: Marek Olšák Part-of: --- diff --git a/src/util/os_socket.c b/src/util/os_socket.c index 98ef013205e..6562cccaddd 100644 --- a/src/util/os_socket.c +++ b/src/util/os_socket.c @@ -33,10 +33,15 @@ os_socket_listen_abstract(const char *path, int count) int ret = bind(s, (struct sockaddr*)&addr, offsetof(struct sockaddr_un, sun_path) + strlen(path) + 1); - if (ret < 0) + if (ret < 0) { + close(s); return -1; + } - listen(s, count); + if (listen(s, count) < 0) { + close(s); + return -1; + } return s; }