Skip to content

Commit ef9ff15

Browse files
authored
[NFC][analyzer] Rewrite comment header of MallocChecker (#165443)
This commit rewrites the big comment block at the beginning of MallocChecker because it contained lots of obsolete and inaccurate information. I see that this block is a bit verbose (especially compared to the analogous comments in other checkers), but as this is one of the most complex checker families, I think it's useful to give this overview at the beginning of the source file.
1 parent e17bc1e commit ef9ff15

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,45 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file defines a variety of memory management related checkers, such as
9+
// This file defines checkers that report memory management errors such as
1010
// leak, double free, and use-after-free.
1111
//
12-
// The following checkers are defined here:
12+
// The logic for modeling memory allocations is implemented in the checker
13+
// family which is called 'MallocChecker' for historical reasons. (This name is
14+
// inaccurate, something like 'DynamicMemory' would be more precise.)
1315
//
14-
// * MallocChecker
15-
// Despite its name, it models all sorts of memory allocations and
16-
// de- or reallocation, including but not limited to malloc, free,
17-
// relloc, new, delete. It also reports on a variety of memory misuse
18-
// errors.
19-
// Many other checkers interact very closely with this checker, in fact,
20-
// most are merely options to this one. Other checkers may register
21-
// MallocChecker, but do not enable MallocChecker's reports (more details
22-
// to follow around its field, ChecksEnabled).
23-
// It also has a boolean "Optimistic" checker option, which if set to true
24-
// will cause the checker to model user defined memory management related
25-
// functions annotated via the attribute ownership_takes, ownership_holds
26-
// and ownership_returns.
16+
// The reports produced by this backend are exposed through several frontends:
17+
// * MallocChecker: reports all misuse of dynamic memory allocated by
18+
// malloc, related functions (like calloc, realloc etc.) and the functions
19+
// annotated by ownership_returns. (Here the name "MallocChecker" is
20+
// reasonably accurate; don't confuse this checker frontend with the whole
21+
// misnamed family.)
22+
// * NewDeleteChecker: reports most misuse (anything but memory leaks) of
23+
// memory managed by the C++ operators new and new[].
24+
// * NewDeleteLeaksChecker: reports leaks of dynamic memory allocated by
25+
// the C++ operators new and new[].
26+
// * MismatchedDeallocatorChecker: reports situations where the allocation
27+
// and deallocation is mismatched, e.g. memory allocated via malloc is
28+
// passed to operator delete.
29+
// * InnerPointerChecker: reports use of pointers to the internal buffer of
30+
// a std::string instance after operations that invalidate them.
31+
// * TaintedAllocChecker: reports situations where the size argument of a
32+
// memory allocation function or array new operator is tainted (i.e. comes
33+
// from an untrusted source and can be controlled by an attacker).
2734
//
28-
// * NewDeleteChecker
29-
// Enables the modeling of new, new[], delete, delete[] in MallocChecker,
30-
// and checks for related double-free and use-after-free errors.
35+
// In addition to these frontends this file also defines the registration
36+
// functions for "unix.DynamicMemoryModeling". This registers the callbacks of
37+
// the checker family MallocChecker without enabling any of the frontends and
38+
// and handle two checker options which are attached to this "modeling
39+
// checker" because they affect multiple checker frontends.
3140
//
32-
// * NewDeleteLeaksChecker
33-
// Checks for leaks related to new, new[], delete, delete[].
34-
// Depends on NewDeleteChecker.
35-
//
36-
// * MismatchedDeallocatorChecker
37-
// Enables checking whether memory is deallocated with the corresponding
38-
// allocation function in MallocChecker, such as malloc() allocated
39-
// regions are only freed by free(), new by delete, new[] by delete[].
40-
//
41-
// InnerPointerChecker interacts very closely with MallocChecker, but unlike
42-
// the above checkers, it has it's own file, hence the many InnerPointerChecker
43-
// related headers and non-static functions.
41+
// Note that what the users see as the checker "cplusplus.InnerPointer" is a
42+
// combination of the frontend InnerPointerChecker (within this family) which
43+
// emits the bug reports and a separate checker class (also named
44+
// InnerPointerChecker) which is defined in InnerPointerChecker.cpp and does a
45+
// significant part of the modeling. This cooperation is enabled by several
46+
// non-static helper functions that are defined within this translation unit
47+
// and used in InnerPointerChecker.cpp.
4448
//
4549
//===----------------------------------------------------------------------===//
4650

0 commit comments

Comments
 (0)