Memory leak: reverted most of change 461.
This commit is contained in:
parent
d11e93f475
commit
d5d2f0671c
|
@ -188,7 +188,7 @@ AllocType CheckMemoryLeakClass::GetDeallocationType( const TOKEN *tok, const cha
|
||||||
|
|
||||||
static std::list<std::string> callstack;
|
static std::list<std::string> callstack;
|
||||||
|
|
||||||
const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, const char typestr[], const char *varnames[] )
|
const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, const char *varnames[] )
|
||||||
{
|
{
|
||||||
if (Match(tok,"if") || Match(tok,"for") || Match(tok,"while"))
|
if (Match(tok,"if") || Match(tok,"for") || Match(tok,"while"))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -227,7 +227,7 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, const char types
|
||||||
// Check if the function deallocates the variable..
|
// Check if the function deallocates the variable..
|
||||||
while ( ftok && ! Match(ftok,"{") )
|
while ( ftok && ! Match(ftok,"{") )
|
||||||
ftok = ftok->next;
|
ftok = ftok->next;
|
||||||
TOKEN *func = getcode( Tokenizer::gettok(ftok,1), typestr, parname );
|
TOKEN *func = getcode( Tokenizer::gettok(ftok,1), parname );
|
||||||
simplifycode( func );
|
simplifycode( func );
|
||||||
const char *ret = 0;
|
const char *ret = 0;
|
||||||
if (findmatch(func, "goto"))
|
if (findmatch(func, "goto"))
|
||||||
|
@ -290,7 +290,7 @@ extern bool ShowAll;
|
||||||
* varname - name of variable
|
* varname - name of variable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, const char typestr[], const char varname[])
|
TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, const char varname[])
|
||||||
{
|
{
|
||||||
const char *varnames[2];
|
const char *varnames[2];
|
||||||
varnames[0] = varname;
|
varnames[0] = varname;
|
||||||
|
@ -453,7 +453,7 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, const char typestr[], con
|
||||||
// Investigate function calls..
|
// Investigate function calls..
|
||||||
if ( Match(tok, "%var% (") )
|
if ( Match(tok, "%var% (") )
|
||||||
{
|
{
|
||||||
const char *str = call_func(tok, typestr, varnames);
|
const char *str = call_func(tok, varnames);
|
||||||
if ( str )
|
if ( str )
|
||||||
addtoken( str );
|
addtoken( str );
|
||||||
}
|
}
|
||||||
|
@ -461,20 +461,9 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, const char typestr[], con
|
||||||
// Linux lists..
|
// Linux lists..
|
||||||
if ( Match( tok, "[=(,] & %var1% [.[]", varnames ) )
|
if ( Match( tok, "[=(,] & %var1% [.[]", varnames ) )
|
||||||
{
|
{
|
||||||
// Linux list -> the first member of the struct
|
// todo: better checking
|
||||||
std::string pattern("struct " + std::string(typestr) + " {");
|
|
||||||
const TOKEN *tok2 = findmatch(tokens, pattern.c_str());
|
|
||||||
if ( ! tok2 )
|
|
||||||
{
|
|
||||||
addtoken("use");
|
addtoken("use");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
tok2 = findmatch(tok2, "%var% [;,]");
|
|
||||||
if ( !tok2 || Match(tok2, Tokenizer::getstr(tok, 4)) )
|
|
||||||
addtoken("use");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rethead;
|
return rethead;
|
||||||
|
@ -776,11 +765,11 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
|
||||||
|
|
||||||
|
|
||||||
// Simpler but less powerful than "CheckMemoryLeak_CheckScope_All"
|
// Simpler but less powerful than "CheckMemoryLeak_CheckScope_All"
|
||||||
void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char typestr[], const char varname[] )
|
void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[] )
|
||||||
{
|
{
|
||||||
callstack.clear();
|
callstack.clear();
|
||||||
|
|
||||||
TOKEN *tok = getcode( Tok1, typestr, varname );
|
TOKEN *tok = getcode( Tok1, varname );
|
||||||
|
|
||||||
// If the variable is not allocated at all => no memory leak
|
// If the variable is not allocated at all => no memory leak
|
||||||
if (findmatch(tok, "alloc") == 0)
|
if (findmatch(tok, "alloc") == 0)
|
||||||
|
@ -876,10 +865,10 @@ void CheckMemoryLeakClass::CheckMemoryLeak_InFunction()
|
||||||
if (indentlevel>0 && infunc)
|
if (indentlevel>0 && infunc)
|
||||||
{
|
{
|
||||||
if ( Match(tok, "[{};] %type% * %var% [;=]") )
|
if ( Match(tok, "[{};] %type% * %var% [;=]") )
|
||||||
CheckMemoryLeak_CheckScope( tok->next, Tokenizer::getstr(tok, 1), Tokenizer::getstr(tok, 3) );
|
CheckMemoryLeak_CheckScope( tok->next, Tokenizer::getstr(tok, 3) );
|
||||||
|
|
||||||
else if ( Match(tok, "[{};] %type% %type% * %var% [;=]") )
|
else if ( Match(tok, "[{};] %type% %type% * %var% [;=]") )
|
||||||
CheckMemoryLeak_CheckScope( tok->next, Tokenizer::getstr(tok, 2), Tokenizer::getstr(tok, 4) );
|
CheckMemoryLeak_CheckScope( tok->next, Tokenizer::getstr(tok, 4) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,16 +42,16 @@ private:
|
||||||
void CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN *tok1, std::vector<const char *> &classname );
|
void CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN *tok1, std::vector<const char *> &classname );
|
||||||
void CheckMemoryLeak_ClassMembers();
|
void CheckMemoryLeak_ClassMembers();
|
||||||
void CheckMemoryLeak_InFunction();
|
void CheckMemoryLeak_InFunction();
|
||||||
void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char typestr[], const char varname[] );
|
void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[] );
|
||||||
void simplifycode(TOKEN *tok);
|
void simplifycode(TOKEN *tok);
|
||||||
void erase(TOKEN *begin, const TOKEN *end);
|
void erase(TOKEN *begin, const TOKEN *end);
|
||||||
|
|
||||||
TOKEN *getcode(const TOKEN *tok, const char typestr[], const char varname[]);
|
TOKEN *getcode(const TOKEN *tok, const char varname[]);
|
||||||
bool notvar(const TOKEN *tok, const char *varnames[]);
|
bool notvar(const TOKEN *tok, const char *varnames[]);
|
||||||
void instoken(TOKEN *tok, const char str[]);
|
void instoken(TOKEN *tok, const char str[]);
|
||||||
void MemoryLeak( const TOKEN *tok, const char varname[] );
|
void MemoryLeak( const TOKEN *tok, const char varname[] );
|
||||||
void MismatchError( const TOKEN *Tok1, const char varname[] );
|
void MismatchError( const TOKEN *Tok1, const char varname[] );
|
||||||
const char * call_func( const TOKEN *tok, const char typestr[], const char *varnames[] );
|
const char * call_func( const TOKEN *tok, const char *varnames[] );
|
||||||
AllocType GetDeallocationType( const TOKEN *tok, const char *varnames[] );
|
AllocType GetDeallocationType( const TOKEN *tok, const char *varnames[] );
|
||||||
AllocType GetAllocationType( const TOKEN *tok2 );
|
AllocType GetAllocationType( const TOKEN *tok2 );
|
||||||
bool isclass( const std::string &typestr );
|
bool isclass( const std::string &typestr );
|
||||||
|
|
|
@ -117,7 +117,6 @@ private:
|
||||||
TEST_CASE( throw1 );
|
TEST_CASE( throw1 );
|
||||||
|
|
||||||
TEST_CASE( linux_list_1 );
|
TEST_CASE( linux_list_1 );
|
||||||
TEST_CASE( linux_list_2 );
|
|
||||||
|
|
||||||
TEST_CASE( sizeof1 );
|
TEST_CASE( sizeof1 );
|
||||||
}
|
}
|
||||||
|
@ -858,23 +857,6 @@ private:
|
||||||
ASSERT_EQUALS( std::string(""), errout.str() );
|
ASSERT_EQUALS( std::string(""), errout.str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void linux_list_2()
|
|
||||||
{
|
|
||||||
check( "struct AB\n"
|
|
||||||
"{\n"
|
|
||||||
" int a;\n"
|
|
||||||
" int b;\n"
|
|
||||||
"};\n"
|
|
||||||
"void foo()\n"
|
|
||||||
"{\n"
|
|
||||||
" struct AB *ab = new AB;\n"
|
|
||||||
" func(&ab->b);\n"
|
|
||||||
"}\n" );
|
|
||||||
|
|
||||||
ASSERT_EQUALS( std::string("[test.cpp:10]: Memory leak: ab\n"), errout.str() );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void sizeof1()
|
void sizeof1()
|
||||||
|
|
Loading…
Reference in New Issue