Fixes issue #16140: The subprocess module no longer double closes its

child subprocess.PIPE parent file descriptors on child error prior to
exec().

This would lead to race conditions in multithreaded programs where
another thread opened a file reusing the fd which was then closed out
from beneath it by the errant second close.
This commit is contained in:
Gregory P. Smith 2012-11-11 01:41:49 -08:00
commit c2c4cb624b
3 changed files with 42 additions and 3 deletions

View file

@ -1419,9 +1419,6 @@ class Popen(object):
child_exception_type = getattr(
builtins, exception_name.decode('ascii'),
SubprocessError)
for fd in (p2cwrite, c2pread, errread):
if fd != -1:
os.close(fd)
err_msg = err_msg.decode(errors="surrogatepass")
if issubclass(child_exception_type, OSError) and hex_errno:
errno_num = int(hex_errno, 16)