Commit 255da78b authored by Dmitry Frank's avatar Dmitry Frank Committed by Cesanta Bot

Fix socket leak when there are too many open fds

CL: Mongoose Web Server: Fix socket leak when there are too many open file descriptors

Fixes https://github.com/cesanta/mongoose/issues/870

PUBLISHED_FROM=c802b6834a54eca37821d46efde192c527e0a6b7
parent 5d5badfc
...@@ -3914,10 +3914,16 @@ time_t mg_socket_if_poll(struct mg_iface *iface, int timeout_ms) { ...@@ -3914,10 +3914,16 @@ time_t mg_socket_if_poll(struct mg_iface *iface, int timeout_ms) {
/* A hack to make sure all our file descriptos fit into FD_SETSIZE. */ /* A hack to make sure all our file descriptos fit into FD_SETSIZE. */
if (nc->sock >= (sock_t) FD_SETSIZE && try_dup) { if (nc->sock >= (sock_t) FD_SETSIZE && try_dup) {
int new_sock = dup(nc->sock); int new_sock = dup(nc->sock);
if (new_sock >= 0 && new_sock < (sock_t) FD_SETSIZE) { if (new_sock >= 0) {
closesocket(nc->sock); if (new_sock < (sock_t) FD_SETSIZE) {
DBG(("new sock %d -> %d", nc->sock, new_sock)); closesocket(nc->sock);
nc->sock = new_sock; DBG(("new sock %d -> %d", nc->sock, new_sock));
nc->sock = new_sock;
} else {
closesocket(new_sock);
DBG(("new sock is still larger than FD_SETSIZE, disregard"));
try_dup = 0;
}
} else { } else {
try_dup = 0; try_dup = 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment