Memory leaks : Reduce "if { dealloc ; return ; } if return ;" to "if return ;". Related with bug 2458532

This commit is contained in:
Daniel Marjamäki 2008-12-22 14:42:54 +00:00
parent a69ebc6664
commit a148e67168
2 changed files with 27 additions and 0 deletions

View File

@ -930,6 +930,13 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
done = false;
}
// Delete first if in .. "if { dealloc|assign|use ; return ; } if return ;"
if ( TOKEN::Match(tok2, "[;{}] if { dealloc|assign|use ; return ; } if return ;") )
{
erase(tok2, tok2->tokAt(8));
done = false;
}
// Delete second case in "case ; case ;"
while (TOKEN::Match(tok2, "case ; case ;"))
{

View File

@ -89,6 +89,7 @@ private:
TEST_CASE( if5 );
TEST_CASE( if6 ); // Bug 2432631
TEST_CASE( if7 ); // Bug 2401436
TEST_CASE( if8 ); // Bug 2458532
TEST_CASE( alwaysTrue );
@ -535,6 +536,25 @@ private:
ASSERT_EQUALS( std::string(""), errout.str() );
}
void if8()
{
check( "static void f(int i)\n"
"{\n"
" char *c = malloc(50);\n"
" if (i == 1)\n"
" {\n"
" free(c);\n"
" return;\n"
" }\n"
" if (i == 2)\n"
" {\n"
" return;\n"
" }\n"
" free(c);\n"
"}\n" );
ASSERT_EQUALS( std::string("[test.cpp:11]: Memory leak: c\n"), errout.str() );
}