summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>2009-03-03 22:41:26 (GMT)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>2009-03-03 22:41:26 (GMT)
commit0c9881782bc1a72fb9fda571bee195c242160de9 (patch)
treef5bf7e2e1fab943a0c13c34d5c4feb5a2b3ceee8 /Lib
parent5b26fb530bd26a63dac42383bbd8d3f4fd4e125a (diff)
downloadcpython-0c9881782bc1a72fb9fda571bee195c242160de9.zip
cpython-0c9881782bc1a72fb9fda571bee195c242160de9.tar.gz
cpython-0c9881782bc1a72fb9fda571bee195c242160de9.tar.bz2
Merged revisions 70137 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r70137 | hirokazu.yamamoto | 2009-03-04 07:18:14 +0900 | 1 line Issue #5179: Fixed subprocess handle leak on failure on windows. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/subprocess.py47
1 files changed, 15 insertions, 32 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index c461b25..638058e 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -638,21 +638,13 @@ class Popen(object):
c2pread, c2pwrite,
errread, errwrite)
- # On Windows, you cannot just redirect one or two handles: You
- # either have to redirect all three or none. If the subprocess
- # user has only redirected one or two handles, we are
- # automatically creating PIPEs for the rest. We should close
- # these after the process is started. See bug #1124861.
if mswindows:
- if stdin is None and p2cwrite is not None:
- os.close(p2cwrite)
- p2cwrite = None
- if stdout is None and c2pread is not None:
- os.close(c2pread)
- c2pread = None
- if stderr is None and errread is not None:
- os.close(errread)
- errread = None
+ if p2cwrite is not None:
+ p2cwrite = msvcrt.open_osfhandle(p2cwrite.Detach(), 0)
+ if c2pread is not None:
+ c2pread = msvcrt.open_osfhandle(c2pread.Detach(), 0)
+ if errread is not None:
+ errread = msvcrt.open_osfhandle(errread.Detach(), 0)
if bufsize == 0:
bufsize = 1 # Nearly unbuffered (XXX for now)
@@ -737,13 +729,10 @@ class Popen(object):
if stdin is None:
p2cread = GetStdHandle(STD_INPUT_HANDLE)
- if p2cread is not None:
- pass
- elif stdin is None or stdin == PIPE:
+ if p2cread is None:
+ p2cread, _ = CreatePipe(None, 0)
+ elif stdin == PIPE:
p2cread, p2cwrite = CreatePipe(None, 0)
- # Detach and turn into fd
- p2cwrite = p2cwrite.Detach()
- p2cwrite = msvcrt.open_osfhandle(p2cwrite, 0)
elif isinstance(stdin, int):
p2cread = msvcrt.get_osfhandle(stdin)
else:
@@ -753,13 +742,10 @@ class Popen(object):
if stdout is None:
c2pwrite = GetStdHandle(STD_OUTPUT_HANDLE)
- if c2pwrite is not None:
- pass
- elif stdout is None or stdout == PIPE:
+ if c2pwrite is None:
+ _, c2pwrite = CreatePipe(None, 0)
+ elif stdout == PIPE:
c2pread, c2pwrite = CreatePipe(None, 0)
- # Detach and turn into fd
- c2pread = c2pread.Detach()
- c2pread = msvcrt.open_osfhandle(c2pread, 0)
elif isinstance(stdout, int):
c2pwrite = msvcrt.get_osfhandle(stdout)
else:
@@ -769,13 +755,10 @@ class Popen(object):
if stderr is None:
errwrite = GetStdHandle(STD_ERROR_HANDLE)
- if errwrite is not None:
- pass
- elif stderr is None or stderr == PIPE:
+ if errwrite is None:
+ _, errwrite = CreatePipe(None, 0)
+ elif stderr == PIPE:
errread, errwrite = CreatePipe(None, 0)
- # Detach and turn into fd
- errread = errread.Detach()
- errread = msvcrt.open_osfhandle(errread, 0)
elif stderr == STDOUT:
errwrite = c2pwrite
elif isinstance(stderr, int):