Memory leaks : Fixed false positive with return (Bug 2458436)

This commit is contained in:
Daniel Marjamäki 2008-12-25 08:27:07 +00:00
parent 1776fdcdcd
commit 492082f4f2
2 changed files with 28 additions and 0 deletions

View File

@ -549,6 +549,20 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
if ( TOKEN::Match(tok, "return %var1%", varnames) ||
TOKEN::Match(tok, "return & %var1%", varnames) )
addtoken("use");
if (TOKEN::simpleMatch(tok->next(), "("))
{
for (const TOKEN *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next() )
{
if ( tok2->str() == "(" || tok2->str() == ")" )
break;
if ( tok2->str() == varname )
{
addtoken("use");
break;
}
}
}
}
// throw..

View File

@ -111,6 +111,7 @@ private:
TEST_CASE( ret2 );
TEST_CASE( ret3 );
TEST_CASE( ret4 );
TEST_CASE( ret5 ); // Bug 2458436 - return use
TEST_CASE( mismatch1 );
@ -818,6 +819,19 @@ private:
ASSERT_EQUALS( std::string("[test.cpp:4]: Resource leak: p\n"), errout.str() );
}
void ret5()
{
check( "static char * f()\n"
"{\n"
" char *c = new char[50];\n"
" return (c ? c : NULL);\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
void mismatch1()
{
check( "void f()\n"