Merge pull request #226 from scriptum/rpg-fix-function-parameter
CheckMemoryLeak: improve leak checking in function parameters
This commit is contained in:
commit
30b56437c1
|
@ -2714,7 +2714,7 @@ void CheckMemoryLeakNoVar::check()
|
||||||
for (const Token *tok3 = tok2; tok3; tok3 = tok3->previous()) {
|
for (const Token *tok3 = tok2; tok3; tok3 = tok3->previous()) {
|
||||||
if (tok3->str() == "(") {
|
if (tok3->str() == "(") {
|
||||||
// Is it a function call..
|
// Is it a function call..
|
||||||
if (Token::Match(tok3->tokAt(-2), "[;{}] %var% (")) {
|
if (!Token::Match(tok3->tokAt(-2), "= %var% (")) {
|
||||||
const std::string& functionName = tok3->strAt(-1);
|
const std::string& functionName = tok3->strAt(-1);
|
||||||
if (functionName == "delete" ||
|
if (functionName == "delete" ||
|
||||||
functionName == "free" ||
|
functionName == "free" ||
|
||||||
|
|
|
@ -5493,6 +5493,24 @@ private:
|
||||||
" close(fd);\n"
|
" close(fd);\n"
|
||||||
"}");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Allocation with strdup, mkstemp doesn't release it.\n", "", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Allocation with strdup, mkstemp doesn't release it.\n", "", errout.str());
|
||||||
|
|
||||||
|
check("void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" if(TRUE || strcmp(strdup(a), b));\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (error) Allocation with strdup, strcmp doesn't release it.\n", errout.str());
|
||||||
|
|
||||||
|
check("void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" if(!strcmp(strdup(a), b) == 0);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (error) Allocation with strdup, strcmp doesn't release it.\n", errout.str());
|
||||||
|
|
||||||
|
check("void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" 42, strcmp(strdup(a), b);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (error) Allocation with strdup, strcmp doesn't release it.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void missingAssignment() {
|
void missingAssignment() {
|
||||||
|
|
Loading…
Reference in New Issue