util: fix possible fd leaks in os_socket_listen_abstract
authorMarcin Ślusarz <marcin.slusarz@intel.com>
Fri, 24 Jul 2020 15:51:25 +0000 (17:51 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 30 Jul 2020 10:41:00 +0000 (10:41 +0000)
Found by Coverity.

Signed-off-by: Marcin Ślusarz <marcin.slusarz@intel.com>
Fixes: ef5266ebd50 ("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>

src/util/os_socket.c

index 98ef013..6562ccc 100644 (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;
 }