Fixed #446 (memory leak false positive when variable is static)
This commit is contained in:
parent
a6ac747830
commit
9beb73824b
|
@ -1654,6 +1654,13 @@ void CheckMemoryLeakInFunction::check()
|
|||
if (sz < 1)
|
||||
sz = 1;
|
||||
|
||||
if (!Token::Match(tok, "[{};] %type%"))
|
||||
continue;
|
||||
|
||||
// Don't check static variables
|
||||
if (tok->next()->str() == "static")
|
||||
continue;
|
||||
|
||||
if (Token::Match(tok, "[{};] %type% * const| %var% [;=]"))
|
||||
{
|
||||
const int varname_tok = (tok->tokAt(3)->str() != "const" ? 3 : 4);
|
||||
|
|
|
@ -131,6 +131,8 @@ private:
|
|||
TEST_CASE(simple11);
|
||||
TEST_CASE(new_nothrow);
|
||||
|
||||
TEST_CASE(staticvar);
|
||||
|
||||
TEST_CASE(alloc_alloc_1);
|
||||
|
||||
TEST_CASE(use1);
|
||||
|
@ -478,6 +480,21 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:4]: (error) Mismatching allocation and deallocation: p\n", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void staticvar()
|
||||
{
|
||||
check("int f()\n"
|
||||
"{\n"
|
||||
" static char *s = 0;\n"
|
||||
" free(s);\n"
|
||||
" s = malloc(100);\n"
|
||||
" return 123;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void alloc_alloc_1()
|
||||
{
|
||||
check("void foo()\n"
|
||||
|
|
Loading…
Reference in New Issue