Skip to content

Commit

Permalink
lit: Make sure to close any files we open as part of redirection.
Browse files Browse the repository at this point in the history
PR6753.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100032 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ddunbar committed Mar 31, 2010
1 parent 5e1b55d commit c3681d3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion utils/lit/lit/TestRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def executeShCmd(cmd, cfg, cwd, results):
procs = []
input = subprocess.PIPE
stderrTempFiles = []
opened_files = []
# To avoid deadlock, we use a single stderr stream for piped
# output. This is null until we have seen some output using
# stderr.
Expand Down Expand Up @@ -115,6 +116,7 @@ def executeShCmd(cmd, cfg, cwd, results):
# Workaround a Win32 and/or subprocess bug when appending.
if r[1] == 'a':
r[2].seek(0, 2)
opened_files.append(r[2])
result = r[2]
final_redirects.append(result)

Expand Down Expand Up @@ -176,7 +178,7 @@ def executeShCmd(cmd, cfg, cwd, results):
else:
err = ''
procData[i] = (out,err)

# Read stderr out of the temp files.
for i,f in stderrTempFiles:
f.seek(0, 0)
Expand All @@ -199,6 +201,10 @@ def executeShCmd(cmd, cfg, cwd, results):
else:
exitCode = res

# Explicitly close any redirected files.
for f in opened_files:
f.close()

if cmd.negate:
exitCode = not exitCode

Expand Down

0 comments on commit c3681d3

Please sign in to comment.