Issue #22831: Use "with" to avoid possible fd leaks.

This commit is contained in:
Serhiy Storchaka 2015-04-04 11:01:02 +03:00
parent ae2d667ae8
commit 46ba6c8563
10 changed files with 107 additions and 120 deletions

View file

@ -97,8 +97,8 @@ def _main():
except OSError as err:
sys.stdout.write("I/O error: %s\n" % str(err))
sys.exit(1)
lines = fp.read().split("\n")
fp.close()
with fp:
lines = fp.read().split("\n")
prog = re.compile(
"#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)",
re.IGNORECASE)
@ -116,8 +116,8 @@ def _main():
except OSError as err:
sys.stderr.write("I/O error: %s\n" % str(err))
sys.exit(2)
format = fp.read().split("\n")
fp.close()
with fp:
format = fp.read().split("\n")
try:
start = format.index("#--start constants--") + 1
end = format.index("#--end constants--")
@ -133,8 +133,8 @@ def _main():
except OSError as err:
sys.stderr.write("I/O error: %s\n" % str(err))
sys.exit(4)
fp.write("\n".join(format))
fp.close()
with fp:
fp.write("\n".join(format))
if __name__ == "__main__":