Skip to content

Commit

Permalink
Fixes #1532: Fixed leaking duplicate file descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshmurthy committed Jun 24, 2024
1 parent d823211 commit 3e11f53
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions router/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning

Code scanning / GNU C11

'dup' on possibly invalid file descriptor 'fd' Warning

'dup' on possibly invalid file descriptor 'fd'
if (fd1 < 0) {
close(fd1);
fail(pipefd[1], "Can't redirect stdout to /dev/null");
}
close(fd1);

Check warning

Code scanning / GNU C11

double 'close' of file descriptor 'fd1' Warning

double 'close' of file descriptor 'fd1'

int fd2 = dup(fd);

Check warning

Code scanning / GNU C11

'dup' on possibly invalid file descriptor 'fd' Warning

'dup' on possibly invalid file descriptor 'fd'
if (fd2 < 0) {
close(fd2);
fail(pipefd[1], "Can't redirect stderr /dev/null");
}
close(fd2);

Check warning

Code scanning / GNU C11

double 'close' of file descriptor 'fd2' Warning

double 'close' of file descriptor 'fd2'

//
// Set the umask to 0
Expand Down

0 comments on commit 3e11f53

Please sign in to comment.