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 <hongfengchen@xiaomi.com>
This commit is contained in:
hongfengchen 2025-06-10 15:03:17 +08:00 committed by Donny(董九柱)
parent f16a45a854
commit b72f7997a3

View file

@ -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]);
}