From: Josh Stone Date: Tue, 4 Feb 2014 17:46:58 +0000 (-0800) Subject: watch: Don't leak extra fds to the child X-Git-Tag: v3.3.10~107 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=835b6294d18a6ad79ff56aaeb0038bc6d006384b;p=procps-ng watch: Don't leak extra fds to the child Once the write side of the pipe has been duped to stdout for the child, the original pipefd is no longer needed, so it can be closed to avoid leaking to the child. The leak can easily be seen with "watch ls -l /proc/self/fd", but I found this due to "watch lvs" diagnosing itself: File descriptor 4 (pipe:[3163616]) leaked on lvs invocation. Signed-off-by: Josh Stone --- diff --git a/watch.c b/watch.c index 032dfb78..f0a3ec39 100644 --- a/watch.c +++ b/watch.c @@ -387,6 +387,7 @@ static int run_command(char *restrict command, char **restrict command_argv) if (dup2(pipefd[1], 1) < 0) { /* replace stdout with write side of pipe */ xerr(3, _("dup2 failed")); } + close(pipefd[1]); /* once duped, the write fd isn't needed */ dup2(1, 2); /* stderr should default to stdout */ if (flags & WATCH_EXEC) { /* pass command to exec instead of system */