Memory leak : Fixed a problem with a fclose inside an if condition

This commit is contained in:
Daniel Marjamäki 2008-12-28 19:57:50 +00:00
parent 56de5ece91
commit 76239fcdf9
2 changed files with 20 additions and 2 deletions

View File

@ -490,6 +490,13 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
if ( parlevel <= 0 ) if ( parlevel <= 0 )
break; break;
} }
if ( TOKEN::Match(tok2, "fclose ( %var1% )", varnames) )
{
addtoken( "dealloc" );
addtoken( ";" );
dep = true;
break;
}
if ( (tok2->str() != ".") && if ( (tok2->str() != ".") &&
TOKEN::Match(tok2->next(), "%var1%", varnames) && TOKEN::Match(tok2->next(), "%var1%", varnames) &&
!TOKEN::Match(tok2->next(), "%var1% .", varnames) ) !TOKEN::Match(tok2->next(), "%var1% .", varnames) )

View File

@ -68,6 +68,7 @@ private:
TEST_CASE( simple7 ); TEST_CASE( simple7 );
TEST_CASE( simple8 ); TEST_CASE( simple8 );
TEST_CASE( simple9 ); // Bug 2435468 - member function "free" TEST_CASE( simple9 ); // Bug 2435468 - member function "free"
TEST_CASE( simple10 ); // fclose in a if condition
TEST_CASE( use1 ); TEST_CASE( use1 );
TEST_CASE( use2 ); TEST_CASE( use2 );
@ -255,6 +256,16 @@ private:
ASSERT_EQUALS( std::string(""), errout.str() ); ASSERT_EQUALS( std::string(""), errout.str() );
} }
void simple10()
{
check( "void foo()\n"
"{\n"
" FILE * f = fopen(fname, str);\n"
" if ( fclose(f) != NULL );\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}