Mesa (staging/20.1): util: fix possible fd leaks in os_socket_listen_abstract
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Aug 2 18:02:13 UTC 2020
Module: Mesa
Branch: staging/20.1
Commit: e159634bf494313a5437d52857e8e8e55400120e
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e159634bf494313a5437d52857e8e8e55400120e
Author: Marcin Ślusarz <marcin.slusarz at intel.com>
Date: Fri Jul 24 17:51:25 2020 +0200
util: fix possible fd leaks in os_socket_listen_abstract
Found by Coverity.
Signed-off-by: Marcin Ślusarz <marcin.slusarz at intel.com>
Fixes: ef5266ebd50 ("util/os_socket: Add socket related functions.")
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6067>
(cherry picked from commit eac0ba7fc193cceccd953bc4726ceef750b18085)
---
.pick_status.json | 2 +-
src/util/os_socket.c | 9 +++++++--
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index 518ac3b9302..0edc1de666f 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -256,7 +256,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"
},
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;
}
More information about the mesa-commit
mailing list