util: fix possible fd leaks in os_socket_listen_abstract

Found by Coverity.

Signed-off-by: Marcin Ślusarz <marcin.slusarz@intel.com>
Fixes: ef5266ebd5 ("util/os_socket: Add socket related functions.")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6067>
This commit is contained in:
Marcin Ślusarz 2020-07-24 17:51:25 +02:00 committed by Marge Bot
parent 62bfc700f7
commit eac0ba7fc1

View file

@ -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;
}