Nettacker
Nettacker copied to clipboard
Resource Leaks: Files not closed properly in multiple modules
Summary
Some Nettacker modules use open().read() without context managers, which can leave file handles open and cause resource leaks. This can lead to exhaustion of file descriptors in long‑running processes.
Problem
The following module contain unsafe file reads:
| File | Fix Applied |
|---|---|
nettacker/lib/html_log/log_data.py |
HTML template reads |
nettacker/lib/graph/d3_tree_v1/engine.py |
D3 tree template read |
nettacker/lib/compare_report/engine.py |
Compare report template read |
Resolution
Replace all bare open() calls with context managers:
# Before (unsafe)
content = open(filename).read()
# After (safe)
with open(filename) as f:
content = f.read()
Testing
-
Add new pytest tests under tests/lib/ to confirm:
-
Files are read correctly.
-
File handles are closed after reading.
-
Edge cases (empty file, missing file) are handled properly.