summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Golden <mail@timgolden.me.uk>2010-08-06 13:03:56 (GMT)
committerTim Golden <mail@timgolden.me.uk>2010-08-06 13:03:56 (GMT)
commitaf5ac3974b7dbf824c8ed560c7dd5588fab0d419 (patch)
treeee9b31e845c44c2645e177efdd2e50b5f3f296e1 /Lib
parent2e3d539ce2d4b91e3353e890858f8f8de6215d25 (diff)
downloadcpython-af5ac3974b7dbf824c8ed560c7dd5588fab0d419.zip
cpython-af5ac3974b7dbf824c8ed560c7dd5588fab0d419.tar.gz
cpython-af5ac3974b7dbf824c8ed560c7dd5588fab0d419.tar.bz2
Issue #3210: Ensure stdio handles are closed if CreateProcess fails
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_subprocess.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index eb0f5d7..95da107 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -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):