Browse Source

Fix extremely unlikely race on fd being accessed before it is set to -1 on closing

master
Con Kolivas 9 years ago
parent
commit
c1f812effc
  1. 12
      src/libckpool.c

12
src/libckpool.c

@ -620,13 +620,17 @@ void block_socket(int fd)
void _close(int *fd, const char *file, const char *func, const int line)
{
int sockd;
if (*fd < 0)
return;
LOGDEBUG("Closing file handle %d", *fd);
if (unlikely(close(*fd)))
LOGWARNING("Close of fd %d failed with errno %d:%s from %s %s:%d",
*fd, errno, strerror(errno), file, func, line);
sockd = *fd;
LOGDEBUG("Closing file handle %d", sockd);
*fd = -1;
if (unlikely(close(sockd))) {
LOGWARNING("Close of fd %d failed with errno %d:%s from %s %s:%d",
sockd, errno, strerror(errno), file, func, line);
}
}
int bind_socket(char *url, char *port)

Loading…
Cancel
Save