detect memory leak when all is given when calling an unknown function

This commit is contained in:
Daniel Marjamäki 2009-06-21 13:48:39 +02:00
parent a0ba52ccf1
commit f28dec1f5a
2 changed files with 29 additions and 0 deletions

View File

@ -988,6 +988,22 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
tok2 = tokEnd;
}
// If "--all" is given, remove all "callfunc"..
if (_settings->_showAll)
{
Token *tok2 = tok;
while (tok2)
{
if (tok2->str() == "callfunc")
{
tok2->deleteThis();
all = true;
}
else
tok2 = tok2->next();
}
}
// reduce the code..
bool done = false;
while (! done)

View File

@ -254,6 +254,7 @@ private:
TEST_CASE(unknownFunction1);
TEST_CASE(unknownFunction2);
TEST_CASE(unknownFunction3);
TEST_CASE(unknownFunction4);
// VCL..
TEST_CASE(vcl1);
@ -1951,6 +1952,18 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str());
}
void unknownFunction4()
{
check("void foo()\n"
"{\n"
" int *p = new int[100];\n"
" a();\n"
" if (b) return;\n"
" delete [] p;\n"
"}\n", true);
ASSERT_EQUALS("[test.cpp:5]: (all) Memory leak: p\n", errout.str());
}
void checkvcl(const char code[], const char _autoDealloc[])