Memory leak : Fix to avoid false positives
This commit is contained in:
parent
dec4561ce3
commit
cf355c9e75
|
@ -602,7 +602,7 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
|
|||
if ( TOKEN::Match( tok, "[=(,] & %var1% [.[]", varnames ) )
|
||||
{
|
||||
// todo: better checking
|
||||
addtoken("use");
|
||||
addtoken("&use");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1091,6 +1091,13 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const
|
|||
_errorLogger->reportErr( errmsg.str() );
|
||||
}
|
||||
|
||||
// Replace "&use" with "use"
|
||||
for ( TOKEN *tok2 = tok; tok2; tok2 = tok2->next() )
|
||||
{
|
||||
if (tok2->str() == "&use")
|
||||
tok2->setstr("use");
|
||||
}
|
||||
|
||||
simplifycode( tok );
|
||||
//tok->printOut( "simplifycode result" );
|
||||
|
||||
|
|
|
@ -153,6 +153,7 @@ private:
|
|||
// TODO TEST_CASE( structmember1 );
|
||||
|
||||
TEST_CASE( dealloc_use_1 ); // Deallocate and then use memory
|
||||
TEST_CASE( dealloc_use_2 ); // Deallocate and then use memory. No error if "use" is &var
|
||||
}
|
||||
|
||||
|
||||
|
@ -1377,6 +1378,17 @@ private:
|
|||
ASSERT_EQUALS( std::string("[test.cpp:5]: Using \"s\" after it has been deallocated / released\n"), errout.str() );
|
||||
}
|
||||
|
||||
void dealloc_use_2()
|
||||
{
|
||||
check( "void f()\n"
|
||||
"{\n"
|
||||
" char *str;\n"
|
||||
" free(str);\n"
|
||||
" foo(&str);\n"
|
||||
"}\n" );
|
||||
ASSERT_EQUALS( std::string(""), errout.str() );
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue