Issue #3210: Ensure stdio handles are closed if CreateProcess fails

This commit is contained in:
Tim Golden 2010-08-06 13:03:56 +00:00
parent 2e3d539ce2
commit af5ac3974b
2 changed files with 37 additions and 2 deletions

View file

@ -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):