mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #3210: Ensure stdio handles are closed if CreateProcess fails
This commit is contained in:
parent
51ced7afe7
commit
40b3744efa
2 changed files with 37 additions and 2 deletions
|
@ -548,6 +548,26 @@ class ProcessTestCase(unittest.TestCase):
|
|||
output = subprocess.check_output([sys.executable, '-c', code])
|
||||
self.assert_(output.startswith(b'Hello World!'), ascii(output))
|
||||
|
||||
def test_handles_closed_on_exception(self):
|
||||
# If CreateProcess exits with an error, ensure the
|
||||
# duplicate output handles are released
|
||||
ifhandle, ifname = self.mkstemp()
|
||||
ofhandle, ofname = self.mkstemp()
|
||||
efhandle, efname = self.mkstemp()
|
||||
try:
|
||||
subprocess.Popen (["*"], stdin=ifhandle, stdout=ofhandle,
|
||||
stderr=efhandle)
|
||||
except OSError:
|
||||
os.close(ifhandle)
|
||||
os.remove(ifname)
|
||||
os.close(ofhandle)
|
||||
os.remove(ofname)
|
||||
os.close(efhandle)
|
||||
os.remove(efname)
|
||||
self.assertFalse(os.path.exists(ifname))
|
||||
self.assertFalse(os.path.exists(ofname))
|
||||
self.assertFalse(os.path.exists(efname))
|
||||
|
||||
#
|
||||
# POSIX tests
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue