From 4345a1ac118e904f4d9f4b77267b4b961cca95a3 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 33f367eebb79dd2..05a4e41500e60c3 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1347,8 +1347,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) @@ -1367,8 +1367,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) @@ -1387,8 +1387,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) @@ -1678,9 +1678,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): @@ -1693,9 +1693,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): @@ -1708,9 +1708,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