aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Preud'homme <thomasp@graphcore.ai>2019-10-14 21:49:21 +0000
committerThomas Preud'homme <thomasp@graphcore.ai>2019-10-14 21:49:21 +0000
commit8c57bba3687ada10de5653ae46c537e957525bdb (patch)
tree9af99a8d7d76360dd04dd86380614a87e7b79ce6
parent446f9a3b651086e87684d643705273ef78045279 (diff)
[LNT] Fix execfile Python 3 migrationHEADmaster
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. git-svn-id: https://llvm.org/svn/llvm-project/lnt/trunk@374824 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lnt/server/db/migrate.py4
-rw-r--r--lnt/server/db/rules_manager.py3
2 files changed, 4 insertions, 3 deletions
diff --git a/lnt/server/db/migrate.py b/lnt/server/db/migrate.py
index b10b84e..e6bfd45 100644
--- a/lnt/server/db/migrate.py
+++ b/lnt/server/db/migrate.py
@@ -162,8 +162,8 @@ def update_schema(engine, versions, available_migrations, schema_name):
upgrade_script = schema_migrations[db_version]
globals = {}
- exec(compile(open(upgrade_script).read(), upgrade_script, 'exec'),
- globals)
+ with open(upgrade_script) as f:
+ exec(compile(f.read(), upgrade_script, 'exec'), globals)
upgrade_method = globals['upgrade']
# Execute the upgrade.
diff --git a/lnt/server/db/rules_manager.py b/lnt/server/db/rules_manager.py
index 1f254e2..71b0fe1 100644
--- a/lnt/server/db/rules_manager.py
+++ b/lnt/server/db/rules_manager.py
@@ -66,7 +66,8 @@ def register_hooks():
global HOOKS_LOADED
for name, path in load_rules().items():
globals = {}
- exec(compile(open(path).read(), path, 'exec'), globals)
+ with open(path) as f:
+ exec(compile(f.read(), path, 'exec'), globals)
DESCRIPTIONS[name] = globals['__doc__']
for hook_name in HOOKS.keys():
if hook_name in globals: