From f9fac7f7770f056790b628e47af91ed3e814246c Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 5 Jul 2017 15:40:25 +0200 Subject: [PATCH] Avoid closing invalid FDs to make Valgrind happier. --- src/server.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/server.c b/src/server.c index a75581b9..57ee43e3 100644 --- a/src/server.c +++ b/src/server.c @@ -1555,7 +1555,11 @@ int restartServer(int flags, mstime_t delay) { /* Close all file descriptors, with the exception of stdin, stdout, strerr * which are useful if we restart a Redis server which is not daemonized. */ - for (j = 3; j < (int)server.maxclients + 1024; j++) close(j); + for (j = 3; j < (int)server.maxclients + 1024; j++) { + /* Test the descriptor validity before closing it, otherwise + * Valgrind issues a warning on close(). */ + if (fcntl(j,F_GETFD) != -1) close(j); + } /* Execute the server with the original command line. */ if (delay) usleep(delay*1000);