Memory leak: Added test case that failed. And fixed it.

This commit is contained in:
Daniel Marjamäki 2008-11-16 05:57:41 +00:00
parent 0a638a57d0
commit d11e93f475
2 changed files with 73 additions and 60 deletions

View File

@ -276,9 +276,8 @@ bool CheckMemoryLeakClass::notvar(const TOKEN *tok, const char *varnames[])
return bool( Match(tok, "! %var1% [;)&|]", varnames) ||
Match(tok, "! ( %var1% )", varnames) ||
Match(tok, "unlikely ( ! %var1% )", varnames) ||
Match(tok, "unlikely ( %var1% == NULL )", varnames) ||
Match(tok, "%var1% == NULL", varnames) ||
Match(tok, "NULL == %var1% [;)&|]", varnames) ||
Match(tok, "unlikely ( %var1% == 0 )", varnames) ||
Match(tok, "0 == %var1% [;)&|]", varnames) ||
Match(tok, "%var1% == 0", varnames) );
}

View File

@ -85,6 +85,7 @@ private:
TEST_CASE( ifelse9 );
TEST_CASE( if1 );
TEST_CASE( if2 );
TEST_CASE( forwhile1 );
TEST_CASE( forwhile2 );
@ -399,6 +400,19 @@ private:
ASSERT_EQUALS( std::string("[test.cpp:6]: Memory leak: p\n"), errout.str() );
}
void if2()
{
check( "void f()\n"
"{\n"
" struct smp_alt_module *smp;\n"
" smp = kzalloc(sizeof(*smp), GFP_KERNEL);\n"
" if (NULL == smp)\n"
" return;\n"
" kfree( smp );\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}