Repository navigation
Conversation
…files) Close the ctu-info files after reading them. The files were only closed by the garbage collector, which gives a ResourceWarning.
dmcppcheck
reviewed
Nov 14, 2026
dmcppcheck
left a comment
Contributor
There was a problem hiding this comment.
AI review
I found no problems. The change fixes the ResourceWarning: each ctu-info file is now closed after it has been read, and also when an exception is raised partway through a file. Results without dev mode are the same as before. There are no earlier review comments.
Testing
- Build: ran
make -j8 cppcheckinpr/, which succeeded. - Unit tests: ran
PYTHONPATH=addons python3 -m pytest -q addons/test/misra_test.py. All 17 passed. - CTU case from the test file header: ran
PYTHONDEVMODE=1 ./cppcheck -q --enable=information --enable=style --addon=misra --inline-suppr addons/test/misra/misra-ctu-*-test.c, swapping in the basemisra.pyfor the comparison.- Base: prints
Whole program analysis failed ... misra.py:4917: ResourceWarning: unclosed file <_io.TextIOWrapper name='739.ctu-info' ...> [internalError], followed by about 60 lines of fallout (unmatched suppressions, "There was critical errors"). - PR: only the normal
Active checkersline.
- Base: prints
- Same files without dev mode: base and PR give identical output.
- Exception while reading: I checked that the file is closed when an exception is raised partway through a file. I called
MisraChecker.analyse_ctu_info()directly from a script, withwarnings.simplefilter('error', ResourceWarning)andpython3 -X dev, on a malformed ctu-info file:This raises{"summary":"MisraTypedefInfo","data":[{"nope":1}]}KeyError 'name'in the loop.- Base: reports
ResourceWarning: unclosed file <... name='bad.ctu-info' ...>. - PR: only the
KeyError, with no warning. The generator is closed while the stack unwinds.
- Base: reports
- Missing file: the generator raises
FileNotFoundErroron the first iteration, so the existingexcept FileNotFoundErrorstill catches it.
Automated review of ab1f31e by Claude. The pull request was built and tested locally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
analyse_ctu_info()does not close the ctu-info files. This gives aResourceWarningin Python dev mode.Before PR:
After PR: no output.