a2be1b
From 835b6294d18a6ad79ff56aaeb0038bc6d006384b Mon Sep 17 00:00:00 2001
a2be1b
From: Josh Stone <jistone@redhat.com>
a2be1b
Date: Tue, 4 Feb 2014 09:46:58 -0800
a2be1b
Subject: [PATCH] watch: Don't leak extra fds to the child
a2be1b
a2be1b
Once the write side of the pipe has been duped to stdout for the child,
a2be1b
the original pipefd is no longer needed, so it can be closed to avoid
a2be1b
leaking to the child.
a2be1b
a2be1b
The leak can easily be seen with "watch ls -l /proc/self/fd", but I
a2be1b
found this due to "watch lvs" diagnosing itself:
a2be1b
a2be1b
    File descriptor 4 (pipe:[3163616]) leaked on lvs invocation.
a2be1b
a2be1b
Signed-off-by: Josh Stone <jistone@redhat.com>
a2be1b
---
a2be1b
 watch.c | 1 +
a2be1b
 1 file changed, 1 insertion(+)
a2be1b
a2be1b
diff --git a/watch.c b/watch.c
a2be1b
index 032dfb7..f0a3ec3 100644
a2be1b
--- a/watch.c
a2be1b
+++ b/watch.c
a2be1b
@@ -387,6 +387,7 @@ static int run_command(char *restrict command, char **restrict command_argv)
a2be1b
 		if (dup2(pipefd[1], 1) < 0) {	/* replace stdout with write side of pipe */
a2be1b
 			xerr(3, _("dup2 failed"));
a2be1b
 		}
a2be1b
+		close(pipefd[1]);		/* once duped, the write fd isn't needed */
a2be1b
 		dup2(1, 2);			/* stderr should default to stdout */
a2be1b
 
a2be1b
 		if (flags & WATCH_EXEC) {	/* pass command to exec instead of system */
a2be1b
-- 
a2be1b
1.8.4.2
a2be1b