mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 00:38:31 +00:00
Redbean fix listen leak (#470)
* Fix release of resources allocated to skipped sockets * Update log messages for consistency
This commit is contained in:
parent
7756e27993
commit
9e86980191
1 changed files with 4 additions and 1 deletions
|
@ -3456,7 +3456,7 @@ static void StoreAsset(char *path, size_t pathlen, char *data, size_t datalen,
|
||||||
}
|
}
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
if (-1 == fcntl(zfd, F_SETLKW, &(struct flock){F_WRLCK})) {
|
if (-1 == fcntl(zfd, F_SETLKW, &(struct flock){F_WRLCK})) {
|
||||||
WARNF("can't place write lock on file descriptor %d: %s", zfd,
|
WARNF("(srvr) can't place write lock on file descriptor %d: %s", zfd,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -6931,6 +6931,7 @@ static void Listen(void) {
|
||||||
}
|
}
|
||||||
if (hasonserverlisten &&
|
if (hasonserverlisten &&
|
||||||
LuaOnServerListen(servers.p[n].fd, ips.p[i], ports.p[j])) {
|
LuaOnServerListen(servers.p[n].fd, ips.p[i], ports.p[j])) {
|
||||||
|
close(servers.p[n].fd);
|
||||||
n--; // skip this server instance
|
n--; // skip this server instance
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -6958,6 +6959,8 @@ static void Listen(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// shrink allocated memory in case some of the sockets were skipped
|
||||||
|
if (n < ips.n * ports.n) servers.p = realloc(servers.p, n*sizeof(*servers.p));
|
||||||
servers.n = n;
|
servers.n = n;
|
||||||
polls = malloc((1 + n) * sizeof(*polls));
|
polls = malloc((1 + n) * sizeof(*polls));
|
||||||
polls[0].fd = -1;
|
polls[0].fd = -1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue