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

@ -1367,6 +1367,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
// just add a "::use" // just add a "::use"
// 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)
{
if (!test_white_list(tok->str()))
{ {
int innerParlevel = 1; int innerParlevel = 1;
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next())
@ -1386,6 +1388,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
} }
} }
} }
}
else else
{ {

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.. // 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));
} }