Make usage of open safer by setting binary mode and closing fds

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-04-18 14:48:03 -07:00
parent accc56d82b
commit 76ca9f8145
4 changed files with 23 additions and 11 deletions

View File

@ -78,7 +78,11 @@ least one of these before using this command."""
if subprocess.Popen(editor + [path]).wait() != 0:
raise EditorError()
return open(path).read()
fd = open(path)
try:
return read()
finally:
fd.close()
finally:
if fd:
os.close(fd)