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) void _close(int *fd, const char *file, const char *func, const int line)
{ {
int sockd;
if (*fd < 0) if (*fd < 0)
return; return;
LOGDEBUG("Closing file handle %d", *fd); sockd = *fd;
if (unlikely(close(*fd))) LOGDEBUG("Closing file handle %d", sockd);
LOGWARNING("Close of fd %d failed with errno %d:%s from %s %s:%d",
*fd, errno, strerror(errno), file, func, line);
*fd = -1; *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) int bind_socket(char *url, char *port)

Loading…
Cancel
Save