Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions net.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ static int redisCreateSocket(redisContext *c, int type) {
return REDIS_ERR;
}
c->fd = s;

/* Prevent file descriptor from leaking to child processes */
if (fcntl(s, F_SETFD, FD_CLOEXEC) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"fcntl(FD_CLOEXEC)");
redisNetClose(c);
return REDIS_ERR;
}

if (type == AF_INET) {
if (redisSetReuseAddr(c) == REDIS_ERR) {
return REDIS_ERR;
Expand Down Expand Up @@ -517,6 +525,16 @@ static int _redisContextConnectTcp(redisContext *c, const char *addr, int port,
continue;

c->fd = s;

#ifndef _WIN32
/* Prevent file descriptor from leaking to child processes */
if (fcntl(s, F_SETFD, FD_CLOEXEC) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"fcntl(FD_CLOEXEC)");
redisNetClose(c);
goto error;
}
#endif

if (redisSetBlocking(c,0) != REDIS_OK)
goto error;
if (c->tcp.source_addr) {
Expand Down
Loading