From 53b46f5198be6876218a79cf9ae73370f3806a6b Mon Sep 17 00:00:00 2001 From: hongfengchen Date: Tue, 10 Jun 2025 15:03:17 +0800 Subject: [PATCH] system/popen: close newfd correctly Fixes a bug where newfd is not properly closed when newfd[0] equals newfd[1]. This can cause file descriptor leaks in certain edge cases where the read and write sides of the pipe are duplicated. Signed-off-by: hongfengchen --- system/popen/popen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/popen/popen.c b/system/popen/popen.c index 5da6cadf1d0..d9286c9592e 100644 --- a/system/popen/popen.c +++ b/system/popen/popen.c @@ -312,7 +312,7 @@ FILE *popen(FAR const char *command, FAR const char *mode) close(newfd[0]); - if (rw) + if (rw && newfd[0] != newfd[1]) { close(newfd[1]); }