Skip to content

Commit c2e156e

Browse files
authored
Fix leaked handle in create_socket (#1554)
Fixes resource leak problem detected by Coverity Scan.
1 parent 7aba293 commit c2e156e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

httplib.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2728,7 +2728,10 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
27282728
if (sock == INVALID_SOCKET) { continue; }
27292729

27302730
#ifndef _WIN32
2731-
if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) { continue; }
2731+
if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) {
2732+
close_socket(sock);
2733+
continue;
2734+
}
27322735
#endif
27332736

27342737
if (tcp_nodelay) {

0 commit comments

Comments
 (0)