// The allocated region symbol tracked by the main analysis.
SymbolRef Sym;
- // The mode we are in, i.e. what kind of diagnostics will be emitted.
- NotificationMode Mode;
+ // The mode we are in, i.e. what kind of diagnostics will be emitted.
+ NotificationMode Mode;
- // A symbol from when the primary region should have been reallocated.
- SymbolRef FailedReallocSymbol;
+ // A symbol from when the primary region should have been reallocated.
+ SymbolRef FailedReallocSymbol;
- public:
- MallocBugVisitor(SymbolRef S)
- : Sym(S), Mode(Normal), FailedReallocSymbol(0) {}
+ bool IsLeak;
+
+ public:
+ MallocBugVisitor(SymbolRef S, bool isLeak = false)
+ : Sym(S), Mode(Normal), FailedReallocSymbol(0), IsLeak(isLeak) {}
virtual ~MallocBugVisitor() {}
const ExplodedNode *PrevN,
BugReporterContext &BRC,
BugReport &BR);
+
+ PathDiagnosticPiece* getEndPath(BugReporterContext &BRC,
+ const ExplodedNode *EndPathNode,
+ BugReport &BR) {
+ if (!IsLeak)
+ return 0;
+
+ PathDiagnosticLocation L =
+ PathDiagnosticLocation::createEndOfPath(EndPathNode,
+ BRC.getSourceManager());
+ // Do not add the statement itself as a range in case of leak.
+ return new PathDiagnosticEventPiece(L, BR.getDescription(), false);
+ }
+
private:
class StackHintGeneratorForReallocationFailed
: public StackHintGeneratorForSymbol {
BugReport *R = new BugReport(*BT_Leak, os.str(), N, LocUsedForUniqueing);
R->markInteresting(Sym);
- R->addVisitor(new MallocBugVisitor(Sym));
+ R->addVisitor(new MallocBugVisitor(Sym, true));
C.EmitReport(R);
}
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
-//CHECK: <key>ranges</key>
-//CHECK: <array>
-//CHECK: <array>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>14</integer>
-//CHECK: <key>col</key><integer>5</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>14</integer>
-//CHECK: <key>col</key><integer>6</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: </array>
-//CHECK: </array>
//CHECK: <key>depth</key><integer>0</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Memory is never released; potential leak of memory pointed to by 'p'</string>
//CHECK: <key>col</key><integer>9</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
-//CHECK: <key>ranges</key>
-//CHECK: <array>
-//CHECK: <array>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>28</integer>
-//CHECK: <key>col</key><integer>9</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>28</integer>
-//CHECK: <key>col</key><integer>14</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: </array>
-//CHECK: </array>
//CHECK: <key>depth</key><integer>0</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Memory is never released; potential leak of memory pointed to by 'buf'</string>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
-//CHECK: <key>ranges</key>
-//CHECK: <array>
-//CHECK: <array>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>76</integer>
-//CHECK: <key>col</key><integer>5</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>76</integer>
-//CHECK: <key>col</key><integer>13</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: </array>
-//CHECK: </array>
//CHECK: <key>depth</key><integer>0</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Memory is never released; potential leak of memory pointed to by 'buf'</string>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
-//CHECK: <key>ranges</key>
-//CHECK: <array>
-//CHECK: <array>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>97</integer>
-//CHECK: <key>col</key><integer>5</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>97</integer>
-//CHECK: <key>col</key><integer>8</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: </array>
-//CHECK: </array>
//CHECK: <key>depth</key><integer>0</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Memory is never released; potential leak of memory pointed to by 'm'</string>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
-//CHECK: <key>ranges</key>
-//CHECK: <array>
-//CHECK: <array>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>102</integer>
-//CHECK: <key>col</key><integer>5</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>102</integer>
-//CHECK: <key>col</key><integer>11</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: </array>
-//CHECK: </array>
//CHECK: <key>depth</key><integer>1</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Memory is never released; potential leak of memory pointed to by 'x'</string>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
-//CHECK: <key>ranges</key>
-//CHECK: <array>
-//CHECK: <array>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>111</integer>
-//CHECK: <key>col</key><integer>5</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>111</integer>
-//CHECK: <key>col</key><integer>9</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: </array>
-//CHECK: </array>
//CHECK: <key>depth</key><integer>1</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Memory is never released; potential leak of memory pointed to by 'x'</string>
//CHECK: <key>col</key><integer>9</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
-//CHECK: <key>ranges</key>
-//CHECK: <array>
-//CHECK: <array>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>120</integer>
-//CHECK: <key>col</key><integer>9</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>120</integer>
-//CHECK: <key>col</key><integer>9</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: </array>
-//CHECK: </array>
//CHECK: <key>depth</key><integer>1</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Memory is never released; potential leak of memory pointed to by 'x'</string>
//CHECK: <key>col</key><integer>9</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
-//CHECK: <key>ranges</key>
-//CHECK: <array>
-//CHECK: <array>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>131</integer>
-//CHECK: <key>col</key><integer>9</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>131</integer>
-//CHECK: <key>col</key><integer>9</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: </array>
-//CHECK: </array>
//CHECK: <key>depth</key><integer>1</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Memory is never released; potential leak of memory pointed to by 'x'</string>
//CHECK: <key>col</key><integer>12</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
-//CHECK: <key>ranges</key>
-//CHECK: <array>
-//CHECK: <array>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>142</integer>
-//CHECK: <key>col</key><integer>12</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>142</integer>
-//CHECK: <key>col</key><integer>29</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: </array>
-//CHECK: </array>
//CHECK: <key>depth</key><integer>1</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Memory is never released; potential leak of memory pointed to by 'x'</string>
//CHECK: <key>col</key><integer>5</integer>
//CHECK: <key>file</key><integer>0</integer>
//CHECK: </dict>
-//CHECK: <key>ranges</key>
-//CHECK: <array>
-//CHECK: <array>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>153</integer>
-//CHECK: <key>col</key><integer>5</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: <dict>
-//CHECK: <key>line</key><integer>153</integer>
-//CHECK: <key>col</key><integer>23</integer>
-//CHECK: <key>file</key><integer>0</integer>
-//CHECK: </dict>
-//CHECK: </array>
-//CHECK: </array>
//CHECK: <key>depth</key><integer>1</integer>
//CHECK: <key>extended_message</key>
//CHECK: <string>Memory is never released; potential leak of memory pointed to by 'x'</string>