[PATCH] redir: Fix double close in dupredirect

Herbert Xu <[email protected]>
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
For a redirection like "> /dev/null" dupredirect will close the
newly opened file descriptor twice in a row because sh_dup2 also
closes the new file descriptor.

Remove the extra close in dupredirect.

Fixes: 509f5b0dcd71 ("redir: Use memfd_create instead of pipe")
Signed-off-by: Herbert Xu <[email protected]>
---
 src/redir.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/redir.c b/src/redir.c
index bf5207d..2505d49 100644
--- a/src/redir.c
+++ b/src/redir.c
@@ -319,11 +319,9 @@ static void dupredirect(union node *redir, int f)
 				sh_dup2(f, fd, -1);
 			return;
 		}
-		f = fd;
+		close(fd);
 	} else
 		sh_dup2(f, fd, f);
-
-	close(f);
 }
 
 int sh_pipe(int pip[2], int memfd)
-- 
2.39.2

-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.