pyln-testing: close 'config.vars' after reading
What changed, and why it matters
This commit fixes a minor resource leak in a Python testing utility. The original code opened a small configuration file but never explicitly closed it. The fix uses Python's 'with' statement to ensure the file is closed automatically after reading. This is a code-quality improvement with no practical security impact.
No security action required. Treat as routine code-quality/test-hygiene cleanup.
Security signals we found
Resource leak (unclosed file handle) in test utility
No untrusted input, network exposure, or privilege boundary crossed
Fix is a standard Python best-practice cleanup
Evidence from the diff
In contrib/pyln-testing/pyln/testing/utils.py, the env() helper previously called open(fname, ‘r’).readlines() without closing the file handle. The patch replaces this with a context manager (with open(…) as f:), guaranteeing the file descriptor is released. The file is a local ‘config.vars’ read during test setup, and the leak is short-lived and bounded.
Changed components
contrib/pyln-testing/pyln/testing/utils.pyenv() helper functionInspect captured patch +2 / −1
diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py
index 6cfb36e7..9c51bded 100644
--- a/contrib/pyln-testing/pyln/testing/utils.py
+++ b/contrib/pyln-testing/pyln/testing/utils.py
@@ -60,7 +60,8 @@ def env(name, default=None):
"""
fname = 'config.vars'
if os.path.exists(fname):
- lines = open(fname, 'r').readlines()
+ with open(fname, 'r') as f:
+ lines = f.readlines()
config = dict([(line.rstrip().split('=', 1)) for line in lines])
else:
config = {}
Why this scored 17/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.