memleak: class function usage (fixing #63)
This commit is contained in:
parent
ca0f007ca4
commit
068b1458c2
|
@ -609,7 +609,8 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
||||||
if (Token::Match(tok, "%var% ("))
|
if (Token::Match(tok, "%var% ("))
|
||||||
{
|
{
|
||||||
// Inside class function.. if the var is passed as a parameter then
|
// Inside class function.. if the var is passed as a parameter then
|
||||||
// just add a "use"
|
// just add a "::use"
|
||||||
|
// The "::use" means that a member function was probably called but it wasn't analyzed further
|
||||||
if (classmember)
|
if (classmember)
|
||||||
{
|
{
|
||||||
int parlevel = 1;
|
int parlevel = 1;
|
||||||
|
@ -625,7 +626,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
||||||
}
|
}
|
||||||
if (tok2->str() == varnameStr)
|
if (tok2->str() == varnameStr)
|
||||||
{
|
{
|
||||||
addtoken("use");
|
addtoken("::use");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1172,6 +1173,8 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
|
||||||
tok2->str("use");
|
tok2->str("use");
|
||||||
else if (tok2->str() == "use_")
|
else if (tok2->str() == "use_")
|
||||||
tok2->str(";");
|
tok2->str(";");
|
||||||
|
else if (tok2->str() == "::use") // Some kind of member function usage. Not analyzed very well.
|
||||||
|
tok2->str("use");
|
||||||
else if (tok2->str() == "recursive")
|
else if (tok2->str() == "recursive")
|
||||||
tok2->str("use");
|
tok2->str("use");
|
||||||
else if (tok2->str() == "dealloc_")
|
else if (tok2->str() == "dealloc_")
|
||||||
|
|
|
@ -141,6 +141,7 @@ private:
|
||||||
TEST_CASE(class5);
|
TEST_CASE(class5);
|
||||||
TEST_CASE(class6);
|
TEST_CASE(class6);
|
||||||
TEST_CASE(class7);
|
TEST_CASE(class7);
|
||||||
|
TEST_CASE(class8);
|
||||||
|
|
||||||
TEST_CASE(throw1);
|
TEST_CASE(throw1);
|
||||||
TEST_CASE(throw2);
|
TEST_CASE(throw2);
|
||||||
|
@ -1348,6 +1349,24 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void class8()
|
||||||
|
{
|
||||||
|
check("class A\n"
|
||||||
|
"{\n"
|
||||||
|
"public:\n"
|
||||||
|
" void a();\n"
|
||||||
|
" void doNothing() { }\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"void A::a()\n"
|
||||||
|
"{\n"
|
||||||
|
" int* c = new int(1);\n"
|
||||||
|
" delete c;\n"
|
||||||
|
" doNothing(c);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue