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>
(cherry picked from commit eac0ba7fc1)
This commit is contained in:
Marcin Ślusarz 2020-07-24 17:51:25 +02:00 committed by Eric Engestrom
parent d0adfbc984
commit 75e81ff0d7
2 changed files with 8 additions and 3 deletions

View file

@ -1822,7 +1822,7 @@
"description": "util: fix possible fd leaks in os_socket_listen_abstract",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"master_sha": null,
"because_sha": "ef5266ebd50e7fa65c56bdb623e12ca8c233b470"
},

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