From 781b069ed813927d00fb53e84731186eb58d9d3a Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Fri, 19 Feb 2016 18:43:20 +0100 Subject: [PATCH] msvcrt: Don't close HANDLE if stdout or stderr is sharing it. Based on Qian Hong patch. Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcrt/file.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 9f35a62101e..fc9f1aeaee0 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -1021,6 +1021,14 @@ int CDECL MSVCRT__close(int fd) TRACE(":fd (%d) handle (%p)\n", fd, info->handle); if (!(info->wxflag & WX_OPEN)) { ret = -1; + } else if (fd == MSVCRT_STDOUT_FILENO && + info->handle == get_ioinfo_nolock(MSVCRT_STDERR_FILENO)->handle) { + msvcrt_free_fd(fd); + ret = 0; + } else if (fd == MSVCRT_STDERR_FILENO && + info->handle == get_ioinfo_nolock(MSVCRT_STDOUT_FILENO)->handle) { + msvcrt_free_fd(fd); + ret = 0; } else { ret = CloseHandle(info->handle) ? 0 : -1; msvcrt_free_fd(fd);