Memory leak: remove the dealloc in "if dealloc ;" if it's not followed
by an "else". This makes the checking stronger.
This commit is contained in:
parent
459711ed00
commit
224b241f9a
|
@ -208,7 +208,7 @@ static bool notvar(const TOKEN *tok, const char *varnames[])
|
|||
Match(tok, "unlikely ( %var1% == NULL )", varnames) ||
|
||||
Match(tok, "%var1% == NULL", varnames) ||
|
||||
Match(tok, "NULL == %var1% [;)&|]", varnames) ||
|
||||
(!Match(tok,".") && Match(tok->next, "%var1% == 0", varnames)) );
|
||||
Match(tok->next, "%var1% == 0", varnames) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -552,6 +552,13 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
done = false;
|
||||
}
|
||||
|
||||
// Remove "if dealloc ;" if there is no else after it..
|
||||
if (Match(tok2,"if dealloc ;") && !Match(gettok(tok2,3),"else"))
|
||||
{
|
||||
erase( tok2, gettok(tok2, 2) );
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Replace "loop ;" with ";"
|
||||
if ( Match(tok2->next, "loop ;") )
|
||||
{
|
||||
|
|
|
@ -69,6 +69,10 @@ private:
|
|||
TEST_CASE( ifelse3 );
|
||||
TEST_CASE( ifelse4 );
|
||||
TEST_CASE( ifelse5 );
|
||||
TEST_CASE( ifelse6 );
|
||||
TEST_CASE( ifelse7 );
|
||||
TEST_CASE( ifelse8 );
|
||||
TEST_CASE( ifelse9 );
|
||||
|
||||
TEST_CASE( forwhile1 );
|
||||
TEST_CASE( forwhile2 );
|
||||
|
@ -187,6 +191,8 @@ private:
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
void ifelse1()
|
||||
{
|
||||
check( "void f()\n"
|
||||
|
@ -311,6 +317,20 @@ private:
|
|||
}
|
||||
|
||||
|
||||
void ifelse9()
|
||||
{
|
||||
check( "static char *f()\n"
|
||||
"{\n"
|
||||
" char *s = new char[10];\n"
|
||||
" if ( ghfgf )\n"
|
||||
" {\n"
|
||||
" delete [] s;\n"
|
||||
" }\n"
|
||||
"}\n" );
|
||||
ASSERT_EQUALS( std::string("[test.cpp:8]: Memory leak: s\n"), errout.str() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue