From 3e11f530528432d5f21a1e861dfc4b5c688cbe23 Mon Sep 17 00:00:00 2001 From: ganeshmurthy Date: Mon, 24 Jun 2024 11:35:39 -0400 Subject: [PATCH] Fixes #1532: Fixed leaking duplicate file descriptor --- router/src/main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/router/src/main.c b/router/src/main.c index a69fb2cae..b11fa0816 100644 --- a/router/src/main.c +++ b/router/src/main.c @@ -168,8 +168,20 @@ static void daemon_process(const char *config_path, const char *python_pkgdir, b close(0); int fd = open("/dev/null", O_RDWR); if (fd != 0) fail(pipefd[1], "Can't redirect stdin to /dev/null"); - if (dup(fd) < 0) fail(pipefd[1], "Can't redirect stdout to /dev/null"); - if (dup(fd) < 0) fail(pipefd[1], "Can't redirect stderr /dev/null"); + + int fd1 = dup(fd); + if (fd1 < 0) { + close(fd1); + fail(pipefd[1], "Can't redirect stdout to /dev/null"); + } + close(fd1); + + int fd2 = dup(fd); + if (fd2 < 0) { + close(fd2); + fail(pipefd[1], "Can't redirect stderr /dev/null"); + } + close(fd2); // // Set the umask to 0