Commit 2457fc2a authored by Guido van Rossum's avatar Guido van Rossum

Improvement to the previous fix suggested by Thomas Bellman: if the

unlink() or fdopen() fail, close the file descriptor and re-raise the
exception.
parent a96c2d40
......@@ -129,8 +129,12 @@ def TemporaryFile(mode='w+b', bufsize=-1, suffix=""):
if os.name == 'posix':
# Unix -- be very careful
fd = os.open(name, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700)
os.unlink(name)
return os.fdopen(fd, mode, bufsize)
try:
os.unlink(name)
return os.fdopen(fd, mode, bufsize)
except:
os.close(fd)
raise
else:
# Non-unix -- can't unlink file that's still open, use wrapper
file = open(name, mode, bufsize)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment