Skip to content

Commit 3a8556e

Browse files
author
Thomas Preud'homme
committed
[LNT] Fix execfile Python 3 migration
Code change in revision r374687 introduced a memory leak because it opens a file for reading in order to execute its content but does not close it. This commit fixes the leak by putting the read and exec into open's context block. llvm-svn: 374824
1 parent 4f27141 commit 3a8556e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lnt/server/db/migrate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def update_schema(engine, versions, available_migrations, schema_name):
162162
upgrade_script = schema_migrations[db_version]
163163

164164
globals = {}
165-
exec(compile(open(upgrade_script).read(), upgrade_script, 'exec'),
166-
globals)
165+
with open(upgrade_script) as f:
166+
exec(compile(f.read(), upgrade_script, 'exec'), globals)
167167
upgrade_method = globals['upgrade']
168168

169169
# Execute the upgrade.

lnt/server/db/rules_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def register_hooks():
6666
global HOOKS_LOADED
6767
for name, path in load_rules().items():
6868
globals = {}
69-
exec(compile(open(path).read(), path, 'exec'), globals)
69+
with open(path) as f:
70+
exec(compile(f.read(), path, 'exec'), globals)
7071
DESCRIPTIONS[name] = globals['__doc__']
7172
for hook_name in HOOKS.keys():
7273
if hook_name in globals:

0 commit comments

Comments
 (0)