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

This commit is contained in:
Nicolas Le Cam 2009-01-02 00:05:08 +00:00
parent 5b42b5777e
commit 2e439d8cea
2 changed files with 29 additions and 8 deletions

View File

@ -587,17 +587,27 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
} }
// Callback.. // Callback..
if ( TOKEN::Match(tok, "( * %var% ) (") || bool matchFirst;
TOKEN::Match(tok, "( %var% ) (") ) if ( (matchFirst = TOKEN::Match(tok, "( %var%")) ||
TOKEN::Match(tok, "( * %var%") )
{ {
for ( const TOKEN *tok2 = tok->tokAt(4); tok2; tok2 = tok2->next() ) int tokIdx = matchFirst ? 2 : 3;
while ( TOKEN::simpleMatch(tok->tokAt(tokIdx), ".") &&
TOKEN::Match(tok->tokAt(tokIdx + 1), "%var%") )
tokIdx += 2;
if ( TOKEN::simpleMatch(tok->tokAt(tokIdx), ") (") )
{ {
if ( TOKEN::Match(tok2, "[;{]") ) for ( const TOKEN *tok2 = tok->tokAt(tokIdx + 2); tok2; tok2 = tok2->next() )
break;
else if ( tok2->str() == varname )
{ {
addtoken("use"); if ( TOKEN::Match(tok2, "[;{]") )
break; break;
else if ( tok2->str() == varname )
{
addtoken("use");
break;
}
} }
} }
} }

View File

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