Fixed ticket #3550 (false positive: (error) Memory pointed to by 'pxpm' is freed twice)
This commit is contained in:
parent
b6afa8a025
commit
589a2461bd
|
@ -2514,8 +2514,17 @@ void CheckOther::checkDoubleFree()
|
||||||
closeDirVariables.clear();
|
closeDirVariables.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If a variable is passed to a function, remove it from the set of previously freed variables
|
// If a variable is passed to a function, remove it from the set of previously freed variables
|
||||||
else if (Token::Match(tok, "%var% (") && !Token::Match(tok, "printf|sprintf|snprintf|fprintf")) {
|
else if (Token::Match(tok, "%var% (") && !Token::Match(tok, "printf|sprintf|snprintf|fprintf|if|while")) {
|
||||||
|
|
||||||
|
// If this is a new function definition, clear all variables
|
||||||
|
if (Token::Match(tok->next()->link(), ") {")) {
|
||||||
|
freedVariables.clear();
|
||||||
|
closeDirVariables.clear();
|
||||||
|
}
|
||||||
|
// If it is a function call, then clear those variables in its argument list
|
||||||
|
else if (Token::Match(tok->next()->link(), ") ;")) {
|
||||||
for (const Token* tok2 = tok->tokAt(2); tok2 != tok->linkAt(1); tok2 = tok2->next()) {
|
for (const Token* tok2 = tok->tokAt(2); tok2 != tok->linkAt(1); tok2 = tok2->next()) {
|
||||||
if (Token::Match(tok2, "%var%")) {
|
if (Token::Match(tok2, "%var%")) {
|
||||||
unsigned int var = tok2->varId();
|
unsigned int var = tok2->varId();
|
||||||
|
@ -2526,6 +2535,7 @@ void CheckOther::checkDoubleFree()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If a pointer is assigned a new value, remove it from the set of previously freed variables
|
// If a pointer is assigned a new value, remove it from the set of previously freed variables
|
||||||
else if (Token::Match(tok, "%var% =")) {
|
else if (Token::Match(tok, "%var% =")) {
|
||||||
|
|
|
@ -329,6 +329,7 @@ public:
|
||||||
c.sizeofForStrncmpError(0);
|
c.sizeofForStrncmpError(0);
|
||||||
c.sizeofForNumericParameterError(0);
|
c.sizeofForNumericParameterError(0);
|
||||||
c.coutCerrMisusageError(0, "cout");
|
c.coutCerrMisusageError(0, "cout");
|
||||||
|
c.doubleFreeError(0, "varname");
|
||||||
|
|
||||||
// style/warning
|
// style/warning
|
||||||
c.cstyleCastError(0);
|
c.cstyleCastError(0);
|
||||||
|
|
|
@ -4679,6 +4679,18 @@ private:
|
||||||
" delete[] p;\n"
|
" delete[] p;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory pointed to by 'p' is freed twice.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Memory pointed to by 'p' is freed twice.\n", errout.str());
|
||||||
|
|
||||||
|
check(
|
||||||
|
"~LineMarker() {"
|
||||||
|
" delete pxpm;"
|
||||||
|
"}"
|
||||||
|
"LineMarker &operator=(const LineMarker &) {"
|
||||||
|
" delete pxpm;"
|
||||||
|
" pxpm = NULL;"
|
||||||
|
" return *this;"
|
||||||
|
"}"
|
||||||
|
);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void coutCerrMisusage() {
|
void coutCerrMisusage() {
|
||||||
|
|
Loading…
Reference in New Issue