[LNT] r374824 - [LNT] Fix execfile Python 3 migration

Thomas Preud'homme via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 14 14:49:22 PDT 2019


Author: thopre
Date: Mon Oct 14 14:49:21 2019
New Revision: 374824

URL: http://llvm.org/viewvc/llvm-project?rev=374824&view=rev
Log:
[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.

Modified:
    lnt/trunk/lnt/server/db/migrate.py
    lnt/trunk/lnt/server/db/rules_manager.py

Modified: lnt/trunk/lnt/server/db/migrate.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/migrate.py?rev=374824&r1=374823&r2=374824&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/migrate.py (original)
+++ lnt/trunk/lnt/server/db/migrate.py Mon Oct 14 14:49:21 2019
@@ -162,8 +162,8 @@ def update_schema(engine, versions, avai
         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.

Modified: lnt/trunk/lnt/server/db/rules_manager.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/rules_manager.py?rev=374824&r1=374823&r2=374824&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/rules_manager.py (original)
+++ lnt/trunk/lnt/server/db/rules_manager.py Mon Oct 14 14:49:21 2019
@@ -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:




More information about the llvm-commits mailing list