memory leak for struct member: fixed false positive when the struct pointer is stored away

This commit is contained in:
Daniel Marjamäki 2009-07-29 11:38:20 +02:00
parent 4e66dc105e
commit 050b85c5eb
2 changed files with 14 additions and 1 deletions

View File

@ -1923,7 +1923,7 @@ void CheckMemoryLeakStructMember::check()
// Locate struct variables..
if (Token::Match(tok, "struct|;|{|} %type% * %var% [=;]"))
{
const Token *vartok = tok->tokAt(3);
const Token * const vartok = tok->tokAt(3);
if (vartok->varId() == 0)
continue;
@ -1970,6 +1970,11 @@ void CheckMemoryLeakStructMember::check()
--indentlevel2;
}
// Unknown usage of struct
/** @todo Check how the struct is used. Only bail out if necessary */
else if (Token::Match(tok2, "[(,] %varid% [,)]", vartok->varId()))
break;
// Struct member is allocated => check if it is also properly deallocated..
else if (Token::Match(tok2, "%varid% . %var% = malloc|strdup|kmalloc (", vartok->varId()))
{

View File

@ -2976,6 +2976,14 @@ private:
" func(abc);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("static void foo()\n"
"{\n"
" struct ABC *abc = malloc(sizeof(struct ABC));\n"
" abclist.push_back(abc);\n"
" abc->a = malloc(10);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void ifelse()