Memory leak : Fixed false positive when using callbacks (Bug 2458510)

This commit is contained in:
Daniel Marjamäki 2008-12-25 07:50:25 +00:00
parent 2692866694
commit 20ae03d0d0
2 changed files with 14 additions and 2 deletions

View File

@ -569,9 +569,10 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
}
// Callback..
if ( TOKEN::Match(tok, "( * %var% ) (") )
if ( TOKEN::Match(tok, "( * %var% ) (") ||
TOKEN::Match(tok, "( %var% ) (") )
{
for ( const TOKEN *tok2 = tok->tokAt(5); tok2; tok2 = tok2->next() )
for ( const TOKEN *tok2 = tok->tokAt(4); tok2; tok2 = tok2->next() )
{
if ( TOKEN::Match(tok2, "[;{]") )
break;

View File

@ -123,6 +123,7 @@ private:
// TODO TEST_CASE( func7 );
TEST_CASE( func8 ); // Using callback
TEST_CASE( func9 ); // Embedding the function call in a if-condition
TEST_CASE( func10 ); // Bug 2458510 - Function pointer
TEST_CASE( class1 );
TEST_CASE( class2 );
@ -969,6 +970,16 @@ private:
ASSERT_EQUALS( std::string(""), errout.str() );
}
void func10()
{
check( "static void f(void (*fnc)(char*))\n"
"{\n"
" char *c = malloc(50);\n"
" (fnc)(c);\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
/*
void func3()