From c2e156e0e0e6af7df6971456255044197678a982 Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Sun, 9 Apr 2023 12:18:44 -0400 Subject: [PATCH] Fix leaked handle in create_socket (#1554) Fixes resource leak problem detected by Coverity Scan. --- httplib.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/httplib.h b/httplib.h index 73e7c1f..2874600 100644 --- a/httplib.h +++ b/httplib.h @@ -2728,7 +2728,10 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port, if (sock == INVALID_SOCKET) { continue; } #ifndef _WIN32 - if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) { continue; } + if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) { + close_socket(sock); + continue; + } #endif if (tcp_nodelay) {