Fixed #1833 (memory leak detected in version 1.37 not detected in 1.43)
This commit is contained in:
parent
ff9d3d0965
commit
6700351ede
|
@ -1306,6 +1306,20 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
|||
Token::Match(tok, "= strcpy|strcat|memmove|memcpy ( %varid% ,", varid) ||
|
||||
Token::Match(tok, "[;{}] %var% [ %varid% ]", varid))
|
||||
{
|
||||
bool used = true;
|
||||
|
||||
if (Token::Match(tok->tokAt(-2), "; %var% = %varid%", varid))
|
||||
{
|
||||
const unsigned int varid2(tok->previous()->varId());
|
||||
if (Token::Match(tok->tokAt(-6), "const %type% * %varid% ;", varid2) ||
|
||||
Token::Match(tok->tokAt(-7), "const struct %type% * %varid% ;", varid2))
|
||||
{
|
||||
// address is taken by pointer constant
|
||||
used = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (used)
|
||||
addtoken("use");
|
||||
}
|
||||
else if (Token::Match(tok->previous(), "[;{}=(,+-*/] %varid% [", varid))
|
||||
|
@ -1823,6 +1837,14 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
|||
done = false;
|
||||
}
|
||||
|
||||
// Replace "loop callfunc ;" with ";"
|
||||
if (Token::simpleMatch(tok2, "loop callfunc ;"))
|
||||
{
|
||||
tok2->deleteThis();
|
||||
tok2->deleteThis();
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Replace "loop if return ;" with "if return ;"
|
||||
if (Token::simpleMatch(tok2->next(), "loop if return"))
|
||||
{
|
||||
|
|
|
@ -518,6 +518,7 @@ private:
|
|||
ASSERT_EQUALS(";;use;", getcode("char *s; s2 = x + s;", "s"));
|
||||
ASSERT_EQUALS(";;use;if{;}", getcode("char *s; if (foo(s)) ;", "s"));
|
||||
ASSERT_EQUALS(";;use;", getcode("char *s; map1[s] = 0;", "s"));
|
||||
ASSERT_EQUALS(";;;;", getcode("char *p; const char *q; q = p;", "p"));
|
||||
|
||||
// return..
|
||||
ASSERT_EQUALS(";;return;", getcode("char *s; return;", "s"));
|
||||
|
@ -712,6 +713,7 @@ private:
|
|||
ASSERT_EQUALS("; callfunc ;", simplifycode(";callfunc;"));
|
||||
ASSERT_EQUALS(";", simplifycode(";callfunc;;"));
|
||||
ASSERT_EQUALS("dealloc ; alloc ; return ; }", simplifycode("while1 { dealloc ; alloc ; } callfunc ; return ; }"));
|
||||
ASSERT_EQUALS(";", simplifycode("loop callfunc ;"));
|
||||
|
||||
// exit..
|
||||
ASSERT_EQUALS("; exit ;", simplifycode("; alloc; exit;"));
|
||||
|
|
Loading…
Reference in New Issue