procps-ng/watch-fd-leak.patch
2014-02-05 12:53:25 +01:00

35 lines
1.1 KiB
Diff

From 835b6294d18a6ad79ff56aaeb0038bc6d006384b Mon Sep 17 00:00:00 2001
From: Josh Stone <jistone@redhat.com>
Date: Tue, 4 Feb 2014 09:46:58 -0800
Subject: [PATCH] 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 <jistone@redhat.com>
---
watch.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/watch.c b/watch.c
index 032dfb7..f0a3ec3 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 */
--
1.8.4.2