From dc638fbda074e5470e3e576e17d404b06f69e569 Mon Sep 17 00:00:00 2001 From: dongshengyuan <545258830@qq.com> Date: Thu, 11 Jun 2026 13:45:00 +0800 Subject: [PATCH] enhance: popen-fdopen-error-handling If fdopen() fails, close the unused pipe fd, free the pid list node, and restore the smart scheduler signal before returning NULL. Previously the fd would leak and the node would be added to pidlist with a NULL fp. Signed-off-by: dongshengyuan <545258830@qq.com> Part-of: --- os/utils.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/os/utils.c b/os/utils.c index a21705078..a53927531 100644 --- a/os/utils.c +++ b/os/utils.c @@ -1111,10 +1111,23 @@ Popen(const char *command, const char *type) if (*type == 'r') { iop = fdopen(pdes[0], type); close(pdes[1]); + if (!iop) + close(pdes[0]); } else { iop = fdopen(pdes[1], type); close(pdes[0]); + if (!iop) + close(pdes[1]); + } + + if (!iop) { + free(cur); +#ifdef HAVE_SETITIMER + if (SmartScheduleEnable() < 0) + perror("signal"); +#endif + return NULL; } cur->fp = iop;