Fixed #2182 (Context sensitive false positive)
This commit is contained in:
parent
28c53cabea
commit
41bbe5d0cf
|
@ -1425,7 +1425,10 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
|||
// The "::use" means that a member function was probably called but it wasn't analyzed further
|
||||
else if (classmember)
|
||||
{
|
||||
if (!test_white_list(tok->str()))
|
||||
if (noreturn.find(tok->str()) != noreturn.end())
|
||||
addtoken(&rettail, tok, "exit");
|
||||
|
||||
else if (!test_white_list(tok->str()))
|
||||
{
|
||||
int innerParlevel = 1;
|
||||
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next())
|
||||
|
@ -2512,6 +2515,7 @@ void CheckMemoryLeakInFunction::check()
|
|||
tok = tok->next();
|
||||
parseFunctionScope(tok, tok1, classmember);
|
||||
tok = tok->link();
|
||||
classmember = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -311,6 +311,7 @@ private:
|
|||
TEST_CASE(func17);
|
||||
TEST_CASE(func18);
|
||||
TEST_CASE(func19); // Ticket #2056 - if (!f(p)) return 0;
|
||||
TEST_CASE(func20); // Ticket #2182 - exit is not handled
|
||||
|
||||
TEST_CASE(allocfunc1);
|
||||
TEST_CASE(allocfunc2);
|
||||
|
@ -1698,6 +1699,43 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void func20()
|
||||
{
|
||||
// Ticket #2182 - false positive when there is unused class.
|
||||
// If the unused class is removed the false positive goes away.
|
||||
// [test.cpp:12]: (error) Deallocating a deallocated pointer: p
|
||||
check("class test {\n"
|
||||
" void f();\n"
|
||||
"};\n"
|
||||
"void test::f() { }\n"
|
||||
"\n"
|
||||
"void b(int i) {\n"
|
||||
" char *p = new char[10];\n"
|
||||
" if (i) {\n"
|
||||
" delete [] p;\n"
|
||||
" exit(0);\n"
|
||||
" }\n"
|
||||
" delete [] p;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// False positive in classmember
|
||||
// same code as above but the implementation is used in the
|
||||
// class member function
|
||||
check("class test {\n"
|
||||
" void f(int i);\n"
|
||||
"};\n"
|
||||
"void test::f(int i) {\n"
|
||||
" char *p = new char[10];\n"
|
||||
" if (i) {\n"
|
||||
" delete [] p;\n"
|
||||
" exit(0);\n"
|
||||
" }\n"
|
||||
" delete [] p;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue