Fixed #2037 (memleak not detected in exit path when variable used)
This commit is contained in:
parent
8e746ca53f
commit
80be31de13
|
@ -1368,21 +1368,24 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
||||||
// The "::use" means that a member function was probably called but it wasn't analyzed further
|
// The "::use" means that a member function was probably called but it wasn't analyzed further
|
||||||
else if (classmember)
|
else if (classmember)
|
||||||
{
|
{
|
||||||
int innerParlevel = 1;
|
if (!test_white_list(tok->str()))
|
||||||
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next())
|
|
||||||
{
|
{
|
||||||
if (tok2->str() == "(")
|
int innerParlevel = 1;
|
||||||
++innerParlevel;
|
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next())
|
||||||
else if (tok2->str() == ")")
|
|
||||||
{
|
{
|
||||||
--innerParlevel;
|
if (tok2->str() == "(")
|
||||||
if (innerParlevel <= 0)
|
++innerParlevel;
|
||||||
|
else if (tok2->str() == ")")
|
||||||
|
{
|
||||||
|
--innerParlevel;
|
||||||
|
if (innerParlevel <= 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (tok2->varId() == varid)
|
||||||
|
{
|
||||||
|
addtoken(&rettail, tok, "::use");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (tok2->varId() == varid)
|
|
||||||
{
|
|
||||||
addtoken(&rettail, tok, "::use");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -410,7 +410,7 @@ private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string getcode(const char code[], const char varname[]) const
|
std::string getcode(const char code[], const char varname[], bool classfunc=false) const
|
||||||
{
|
{
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer;
|
Tokenizer tokenizer;
|
||||||
|
@ -427,7 +427,7 @@ private:
|
||||||
callstack.push_back(0);
|
callstack.push_back(0);
|
||||||
CheckMemoryLeak::AllocType allocType, deallocType;
|
CheckMemoryLeak::AllocType allocType, deallocType;
|
||||||
allocType = deallocType = CheckMemoryLeak::No;
|
allocType = deallocType = CheckMemoryLeak::No;
|
||||||
Token *tokens = checkMemoryLeak.getcode(tokenizer.tokens(), callstack, varId, allocType, deallocType, false, 1);
|
Token *tokens = checkMemoryLeak.getcode(tokenizer.tokens(), callstack, varId, allocType, deallocType, classfunc, 1);
|
||||||
|
|
||||||
// stringify..
|
// stringify..
|
||||||
std::ostringstream ret;
|
std::ostringstream ret;
|
||||||
|
@ -442,7 +442,6 @@ private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void testgetcode()
|
void testgetcode()
|
||||||
{
|
{
|
||||||
// alloc;
|
// alloc;
|
||||||
|
@ -562,6 +561,9 @@ private:
|
||||||
// fcloseall..
|
// fcloseall..
|
||||||
ASSERT_EQUALS(";;alloc;;", getcode("char *s; s = malloc(10); fcloseall();", "s"));
|
ASSERT_EQUALS(";;alloc;;", getcode("char *s; s = malloc(10); fcloseall();", "s"));
|
||||||
ASSERT_EQUALS(";;alloc;dealloc;", getcode("FILE *f; f = fopen(a,b); fcloseall();", "f"));
|
ASSERT_EQUALS(";;alloc;dealloc;", getcode("FILE *f; f = fopen(a,b); fcloseall();", "f"));
|
||||||
|
|
||||||
|
// call memcpy in class function..
|
||||||
|
ASSERT_EQUALS(";;alloc;;", getcode("char *s; s = new char[10]; memcpy(s,a);", "s", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue