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
2e3d539ce2
commit
af5ac3974b
2 changed files with 37 additions and 2 deletions
|
@ -544,6 +544,26 @@ class ProcessTestCase(BaseTestCase):
|
|||
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 = mkstemp()
|
||||
ofhandle, ofname = mkstemp()
|
||||
efhandle, efname = 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))
|
||||
|
||||
|
||||
# context manager
|
||||
class _SuppressCoreFiles(object):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue