mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-28 13:49:01 +08:00
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
This commit is contained in:
parent
5d5badfcee
commit
255da78bed
@ -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. */
|
||||
if (nc->sock >= (sock_t) FD_SETSIZE && try_dup) {
|
||||
int new_sock = dup(nc->sock);
|
||||
if (new_sock >= 0 && new_sock < (sock_t) FD_SETSIZE) {
|
||||
if (new_sock >= 0) {
|
||||
if (new_sock < (sock_t) FD_SETSIZE) {
|
||||
closesocket(nc->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 {
|
||||
try_dup = 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user