memory leak: keep track of --all better
This commit is contained in:
parent
0cdb537a6a
commit
a5f88862b4
|
@ -268,7 +268,7 @@ const char * CheckMemoryLeakClass::call_func(const Token *tok, std::list<const T
|
||||||
while (ftok && (ftok->str() != "{"))
|
while (ftok && (ftok->str() != "{"))
|
||||||
ftok = ftok->next();
|
ftok = ftok->next();
|
||||||
Token *func = getcode(ftok->tokAt(1), callstack, parname, alloctype, dealloctype, false, all, sz);
|
Token *func = getcode(ftok->tokAt(1), callstack, parname, alloctype, dealloctype, false, all, sz);
|
||||||
simplifycode(func);
|
simplifycode(func, all);
|
||||||
const Token *func_ = func;
|
const Token *func_ = func;
|
||||||
while (func_ && func_->str() == ";")
|
while (func_ && func_->str() == ";")
|
||||||
func_ = func_->next();
|
func_ = func_->next();
|
||||||
|
@ -697,7 +697,7 @@ void CheckMemoryLeakClass::erase(Token *begin, const Token *end)
|
||||||
Token::eraseTokens(begin, end);
|
Token::eraseTokens(begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckMemoryLeakClass::simplifycode(Token *tok)
|
void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
|
||||||
{
|
{
|
||||||
// Replace "throw" that is not in a try block with "return"
|
// Replace "throw" that is not in a try block with "return"
|
||||||
int indentlevel = 0;
|
int indentlevel = 0;
|
||||||
|
@ -794,9 +794,14 @@ void CheckMemoryLeakClass::simplifycode(Token *tok)
|
||||||
else if (Token::Match(tok2, "[;{}] if assign|dealloc|use ; !!else"))
|
else if (Token::Match(tok2, "[;{}] if assign|dealloc|use ; !!else"))
|
||||||
{
|
{
|
||||||
if (_settings._showAll)
|
if (_settings._showAll)
|
||||||
|
{
|
||||||
erase(tok2, tok2->tokAt(3));
|
erase(tok2, tok2->tokAt(3));
|
||||||
|
all = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
erase(tok2, tok2->tokAt(2));
|
erase(tok2, tok2->tokAt(2));
|
||||||
|
}
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -862,11 +867,13 @@ void CheckMemoryLeakClass::simplifycode(Token *tok)
|
||||||
{
|
{
|
||||||
if (Token::Match(tok2->next(), "if assign|dealloc|use ; else"))
|
if (Token::Match(tok2->next(), "if assign|dealloc|use ; else"))
|
||||||
{
|
{
|
||||||
|
all = true;
|
||||||
erase(tok2->next(), tok2->tokAt(3));
|
erase(tok2->next(), tok2->tokAt(3));
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
if (Token::Match(tok2, "[;{}] if { assign|dealloc|use ; return ; } !!else"))
|
if (Token::Match(tok2, "[;{}] if { assign|dealloc|use ; return ; } !!else"))
|
||||||
{
|
{
|
||||||
|
all = true;
|
||||||
erase(tok2, tok2->tokAt(8));
|
erase(tok2, tok2->tokAt(8));
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
@ -1211,7 +1218,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
simplifycode(tok);
|
simplifycode(tok, all);
|
||||||
//tok->printOut("simplifycode result");
|
//tok->printOut("simplifycode result");
|
||||||
|
|
||||||
// If the variable is not allocated at all => no memory leak
|
// If the variable is not allocated at all => no memory leak
|
||||||
|
@ -1594,7 +1601,7 @@ Token * CheckMemoryLeakClass::functionParameterCode(const Token *ftok, int param
|
||||||
bool all = false;
|
bool all = false;
|
||||||
std::list<const Token *> callstack;
|
std::list<const Token *> callstack;
|
||||||
Token *code = getcode(ftok, callstack, parname, alloc, dealloc, false, all, 1);
|
Token *code = getcode(ftok, callstack, parname, alloc, dealloc, false, all, 1);
|
||||||
simplifycode(code);
|
simplifycode(code, all);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ private:
|
||||||
* Simplify code e.g. by replacing empty "{ }" with ";"
|
* Simplify code e.g. by replacing empty "{ }" with ";"
|
||||||
* @param tok first token. The tokens list can be modified.
|
* @param tok first token. The tokens list can be modified.
|
||||||
*/
|
*/
|
||||||
void simplifycode(Token *tok);
|
void simplifycode(Token *tok, bool &all);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete tokens between begin and end. E.g. if begin = 1
|
* Delete tokens between begin and end. E.g. if begin = 1
|
||||||
|
|
|
@ -409,7 +409,7 @@ private:
|
||||||
" return;\n"
|
" return;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n", true);
|
"}\n", true);
|
||||||
ASSERT_EQUALS(std::string("[test.cpp:9]: (error) Memory leak: str\n"), errout.str());
|
ASSERT_EQUALS(std::string("[test.cpp:9]: (all) Memory leak: str\n"), errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -900,7 +900,7 @@ private:
|
||||||
check(code.c_str(), false);
|
check(code.c_str(), false);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
check(code.c_str(), true);
|
check(code.c_str(), true);
|
||||||
ASSERT_EQUALS("[test.cpp:12]: (error) Memory leak: str\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:12]: (all) Memory leak: str\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void switch3()
|
void switch3()
|
||||||
|
|
Loading…
Reference in New Issue