From 0d4efba1463431f667b63e34f2aa4ac01ab64b4c Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith [Google LLC]" Date: Fri, 7 Oct 2022 16:59:07 -0700 Subject: [PATCH] Move err_close_fds adds next to pipe creation. --- Lib/subprocess.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 7257c808e197d1..fbc76b8d0f14b2 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1349,8 +1349,8 @@ def _get_handles(self, stdin, stdout, stderr): if p2cread is None: p2cread, _ = _winapi.CreatePipe(None, 0) p2cread = Handle(p2cread) - _winapi.CloseHandle(_) err_close_fds.append(p2cread) + _winapi.CloseHandle(_) elif stdin == PIPE: p2cread, p2cwrite = _winapi.CreatePipe(None, 0) p2cread, p2cwrite = Handle(p2cread), Handle(p2cwrite) @@ -1369,8 +1369,8 @@ def _get_handles(self, stdin, stdout, stderr): if c2pwrite is None: _, c2pwrite = _winapi.CreatePipe(None, 0) c2pwrite = Handle(c2pwrite) - _winapi.CloseHandle(_) err_close_fds.append(c2pwrite) + _winapi.CloseHandle(_) elif stdout == PIPE: c2pread, c2pwrite = _winapi.CreatePipe(None, 0) c2pread, c2pwrite = Handle(c2pread), Handle(c2pwrite) @@ -1389,8 +1389,8 @@ def _get_handles(self, stdin, stdout, stderr): if errwrite is None: _, errwrite = _winapi.CreatePipe(None, 0) errwrite = Handle(errwrite) - _winapi.CloseHandle(_) err_close_fds.append(errwrite) + _winapi.CloseHandle(_) elif stderr == PIPE: errread, errwrite = _winapi.CreatePipe(None, 0) errread, errwrite = Handle(errread), Handle(errwrite) @@ -1696,9 +1696,9 @@ def _get_handles(self, stdin, stdout, stderr): pass elif stdin == PIPE: p2cread, p2cwrite = os.pipe() + err_close_fds.extend((p2cread, p2cwrite)) if self.pipesize > 0 and hasattr(fcntl, "F_SETPIPE_SZ"): fcntl.fcntl(p2cwrite, fcntl.F_SETPIPE_SZ, self.pipesize) - err_close_fds.extend((p2cread, p2cwrite)) elif stdin == DEVNULL: p2cread = self._get_devnull() elif isinstance(stdin, int): @@ -1711,9 +1711,9 @@ def _get_handles(self, stdin, stdout, stderr): pass elif stdout == PIPE: c2pread, c2pwrite = os.pipe() + err_close_fds.extend((c2pread, c2pwrite)) if self.pipesize > 0 and hasattr(fcntl, "F_SETPIPE_SZ"): fcntl.fcntl(c2pwrite, fcntl.F_SETPIPE_SZ, self.pipesize) - err_close_fds.extend((c2pread, c2pwrite)) elif stdout == DEVNULL: c2pwrite = self._get_devnull() elif isinstance(stdout, int): @@ -1726,9 +1726,9 @@ def _get_handles(self, stdin, stdout, stderr): pass elif stderr == PIPE: errread, errwrite = os.pipe() + err_close_fds.extend((errread, errwrite)) if self.pipesize > 0 and hasattr(fcntl, "F_SETPIPE_SZ"): fcntl.fcntl(errwrite, fcntl.F_SETPIPE_SZ, self.pipesize) - err_close_fds.extend((errread, errwrite)) elif stderr == STDOUT: if c2pwrite != -1: errwrite = c2pwrite