Issue #6274. Fixed a potential FD leak in subprocess.py.
This commit is contained in:
parent
5fe420e34c
commit
8c826b77e0
|
@ -1056,6 +1056,8 @@ class Popen(object):
|
|||
# The first char specifies the exception type: 0 means
|
||||
# OSError, 1 means some other error.
|
||||
errpipe_read, errpipe_write = os.pipe()
|
||||
try:
|
||||
try:
|
||||
self._set_cloexec_flag(errpipe_write)
|
||||
|
||||
gc_was_enabled = gc.isenabled()
|
||||
|
@ -1129,7 +1131,10 @@ class Popen(object):
|
|||
# Parent
|
||||
if gc_was_enabled:
|
||||
gc.enable()
|
||||
finally:
|
||||
# be sure the FD is closed no matter what
|
||||
os.close(errpipe_write)
|
||||
|
||||
if p2cread is not None and p2cwrite is not None:
|
||||
os.close(p2cread)
|
||||
if c2pwrite is not None and c2pread is not None:
|
||||
|
@ -1138,8 +1143,11 @@ class Popen(object):
|
|||
os.close(errwrite)
|
||||
|
||||
# Wait for exec to fail or succeed; possibly raising exception
|
||||
data = os.read(errpipe_read, 1048576) # Exceptions limited to 1 MB
|
||||
data = os.read(errpipe_read, 1048576) # Exception limited to 1M
|
||||
finally:
|
||||
# be sure the FD is closed no matter what
|
||||
os.close(errpipe_read)
|
||||
|
||||
if data != "":
|
||||
os.waitpid(self.pid, 0)
|
||||
child_exception = pickle.loads(data)
|
||||
|
|
Loading…
Reference in New Issue