This is an automated email from the ASF dual-hosted git repository.
jiuzhudong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new b72f7997a system/popen: close newfd correctly
b72f7997a is described below
commit b72f7997a35cb959ff35b7b1c03e5053953752e6
Author: hongfengchen <[email protected]>
AuthorDate: Tue Jun 10 15:03:17 2025 +0800
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 <[email protected]>
---
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 5da6cadf1..d9286c959 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]);
}