memleak: *x=malloc(); func(&x) is no longer reported as a leak (eliminated &use2).

This commit is contained in:
Leandro Penz 2009-01-24 18:55:56 +00:00
parent 835a749026
commit 04faae2882
2 changed files with 16 additions and 7 deletions

View File

@ -652,14 +652,10 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
} }
// Linux lists.. // Linux lists..
if (Token::Match(tok, std::string("[=(,] & " + varnameStr + " [.[]").c_str())) if (Token::Match(tok, std::string("[=(,] & " + varnameStr + " [.[,)]").c_str()))
{ {
addtoken("&use"); addtoken("&use");
} }
else if (Token::Match(tok, std::string("[=(,] & " + varnameStr + " [,)]").c_str()))
{
addtoken("&use2");
}
} }
return rethead; return rethead;
@ -1155,12 +1151,12 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
_errorLogger->reportErr(errmsg.str()); _errorLogger->reportErr(errmsg.str());
} }
// Replace "&use" with "use". Replace "&use2" with ";" // Replace "&use" with "use". Replace "use_" with ";"
for (Token *tok2 = tok; tok2; tok2 = tok2->next()) for (Token *tok2 = tok; tok2; tok2 = tok2->next())
{ {
if (tok2->str() == "&use") if (tok2->str() == "&use")
tok2->str("use"); tok2->str("use");
else if (tok2->str() == "&use2" || tok2->str() == "use_") else if (tok2->str() == "use_")
tok2->str(";"); tok2->str(";");
else if (tok2->str() == "recursive") else if (tok2->str() == "recursive")
tok2->str("use"); tok2->str("use");

View File

@ -132,6 +132,7 @@ private:
TEST_CASE(func10); // Bug 2458510 - Function pointer TEST_CASE(func10); // Bug 2458510 - Function pointer
TEST_CASE(func11); // Bug 2458510 - Function pointer TEST_CASE(func11); // Bug 2458510 - Function pointer
TEST_CASE(func12); TEST_CASE(func12);
TEST_CASE(func13);
TEST_CASE(class1); TEST_CASE(class1);
TEST_CASE(class2); TEST_CASE(class2);
@ -1131,6 +1132,18 @@ private:
ASSERT_EQUALS(std::string(""), errout.str()); ASSERT_EQUALS(std::string(""), errout.str());
} }
void func13()
{
check("static void f()\n"
"{\n"
" char *p = malloc(100);\n"
" foo(&p);\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
/* /*
void func3() void func3()