Report resource leaks with non-fatal error.
Report every resource leak.
Stream state is cleaned up at checkDeadSymbols.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Why does this not work?
I get only warning for the first resource leak (in the test f_leak_2). How to fix this?
First off, are two errors detected by the checker? You could check this with debug.ViewExplodedGraph + clang/tools/analyzer/exploded-graph-rewriter.py.
I do suspect though that this is a uniqueing issue. Just out of curiosity, what would happen is you dump the leaked stream symbol into the warning message? (or whatever, just so that two distinct warning messages are emitted)
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp | ||
---|---|---|
969 | It is a realistic worry that either the predecessor exploded node or the CFGBlock is null? Could we assert this instead? | |
971 | Ah, I see, we made it fatal accidentally. |
I checked it with simple debug print, the LeakedSyms will contain 2 items with different StreamOpenNode. So I think these should be independent problem reports for the bug reporter.
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp | ||
---|---|---|
969 | It may be simply more safe to check for it. I do not know if exactly if these can be null at this place. |
It would still be beneficial to check the exploded graph to see whether it was constructed correctly, find the error nodes, etc. Have you tried modifying the warning message? That is considered during uniquing.
I recall that i did something similar in UninitializedObjectChecker when the option NotesAsWarnings is true.
The problem is that PathDiagnostic::Profile does not use the uniqueing locations. Two PathDiagnostic objects with different uniqueing location but otherwise same data are counted as "same" and only one is kept (BugReporter::FlushReport). How to fix this?
- Add uniqueing locations to the profile. May have unexpected effects to other checkers.
- Change something in the leak bug reports to make these different. Probably the location can be set to the allocation site (but the full path should be reported). Or include name of the leaked symbol in the report, but it may not exists always.
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp | ||
---|---|---|
969 | Please use SuppressOnSink instead. |
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp | ||
---|---|---|
969 | That was my plan for the next patch. So I want to leave this as is for now (add a FIXME), it should be removed anyway. |
Ah, I see, we made it fatal accidentally.