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:
parent
accc56d82b
commit
76ca9f8145
4 changed files with 23 additions and 11 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue