Merge pull request #226 from scriptum/rpg-fix-function-parameter

CheckMemoryLeak: improve leak checking in function parameters
This commit is contained in:
Daniel Marjamäki 2014-01-28 20:32:56 -08:00
commit 30b56437c1
2 changed files with 19 additions and 1 deletions

View File

@ -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" ||

View File

@ -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() {