Fixed #746 (False positive, Memory leak when goto is used)
This commit is contained in:
parent
1427f0a2c7
commit
311f6dc92e
|
@ -2116,10 +2116,17 @@ void CheckMemoryLeakStructMember::check()
|
|||
ignoredFunctions.insert("while");
|
||||
ignoredFunctions.insert("malloc");
|
||||
|
||||
|
||||
unsigned int indentlevel1 = 0;
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||
{
|
||||
if (tok->str() == "{")
|
||||
++indentlevel1;
|
||||
else if (tok->str() == "}")
|
||||
--indentlevel1;
|
||||
|
||||
// Locate struct variables..
|
||||
if (Token::Match(tok, "struct|;|{|} %type% * %var% [=;]"))
|
||||
if (indentlevel1 > 0 && Token::Match(tok, "struct|;|{|} %type% * %var% [=;]"))
|
||||
{
|
||||
const Token * const vartok = tok->tokAt(3);
|
||||
if (vartok->varId() == 0)
|
||||
|
|
|
@ -2733,6 +2733,9 @@ private:
|
|||
|
||||
// Handle if-else
|
||||
TEST_CASE(ifelse);
|
||||
|
||||
// struct variable is a global variable
|
||||
TEST_CASE(globalvar);
|
||||
}
|
||||
|
||||
void err()
|
||||
|
@ -2896,6 +2899,19 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void globalvar()
|
||||
{
|
||||
check("struct ABC *abc;\n"
|
||||
"\n"
|
||||
"static void foo()\n"
|
||||
"{\n"
|
||||
" abc = malloc(sizeof(struct ABC));\n"
|
||||
" abc->a = malloc(10);\n"
|
||||
" return;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue