Fixed #2037 (memleak not detected in exit path when variable used)

This commit is contained in:
Daniel Marjamäki 2010-09-08 20:03:22 +02:00
parent 8e746ca53f
commit 80be31de13
2 changed files with 20 additions and 15 deletions

View File

@ -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
else if (classmember)
{
int innerParlevel = 1;
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next())
if (!test_white_list(tok->str()))
{
if (tok2->str() == "(")
++innerParlevel;
else if (tok2->str() == ")")
int innerParlevel = 1;
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next())
{
--innerParlevel;
if (innerParlevel <= 0)
if (tok2->str() == "(")
++innerParlevel;
else if (tok2->str() == ")")
{
--innerParlevel;
if (innerParlevel <= 0)
break;
}
if (tok2->varId() == varid)
{
addtoken(&rettail, tok, "::use");
break;
}
if (tok2->varId() == varid)
{
addtoken(&rettail, tok, "::use");
break;
}
}
}
}

View File

@ -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..
Tokenizer tokenizer;
@ -427,7 +427,7 @@ private:
callstack.push_back(0);
CheckMemoryLeak::AllocType allocType, deallocType;
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..
std::ostringstream ret;
@ -442,7 +442,6 @@ private:
void testgetcode()
{
// alloc;
@ -562,6 +561,9 @@ private:
// fcloseall..
ASSERT_EQUALS(";;alloc;;", getcode("char *s; s = malloc(10); fcloseall();", "s"));
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));
}