Skip to content

Commit f6a3db0

Browse files
authored
Fix #15215 (misra.py: analyse_ctu_info() does not close the ctu-info files) (#9025)
`analyse_ctu_info()` does not close the ctu-info files. This gives a `ResourceWarning` in Python dev mode. ``` PYTHONDEVMODE=1 cppcheck -q --addon=misra addons/test/misra/misra-ctu-1-test.c addons/test/misra/misra-ctu-2-test.c ``` Before PR: ``` :0:0: error: Bailing out from analysis: Whole program analysis failed: Failed to execute 'python3.exe ...\addons\runaddon.py ...\addons\misra.py --cli 22364.ctu-info'. ...\addons\misra.py:4917: ResourceWarning: unclosed file <_io.TextIOWrapper name='22364.ctu-info' mode='rt' encoding='utf-8'> [internalError] ``` After PR: no output.
1 parent a05fbed commit f6a3db0

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎addons/misra.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4912,9 +4912,13 @@ def is_different_location(loc1, loc2):
49124912
def is_different_file(loc1, loc2):
49134913
return loc1['file'] != loc2['file']
49144914

4915+
def read_lines(filename):
4916+
with open(filename, 'rt') as f:
4917+
yield from f
4918+
49154919
try:
49164920
for filename in ctu_info_files:
4917-
for line in open(filename, 'rt'):
4921+
for line in read_lines(filename):
49184922
s = self.read_ctu_info_line(line)
49194923
if s is None:
49204924
continue

0 commit comments

Comments
 (0)