checkmemoryleak: no longer flag "dealloc ; alloc ; if continue ;" as a leak, even with --all
This commit is contained in:
parent
1a4cfc6c4f
commit
5570f06075
|
@ -1172,7 +1172,8 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
|
|||
MemoryLeak(result, varname, alloctype);
|
||||
}
|
||||
|
||||
else if ((result = Token::findmatch(tok, "alloc ; if break|continue|return ;")) != NULL)
|
||||
else if ((result = Token::findmatch(tok, "alloc ; if break|continue|return ;")) != NULL
|
||||
&& Token::findmatch(tok, "dealloc ; alloc ; if continue ;") == NULL)
|
||||
{
|
||||
MemoryLeak(result->tokAt(3), varname, alloctype);
|
||||
}
|
||||
|
|
|
@ -102,6 +102,8 @@ private:
|
|||
TEST_CASE(forwhile6);
|
||||
TEST_CASE(forwhile7);
|
||||
TEST_CASE(forwhile8); // Bug 2429936
|
||||
TEST_CASE(forwhile9);
|
||||
TEST_CASE(forwhile10);
|
||||
|
||||
TEST_CASE(dowhile1);
|
||||
|
||||
|
@ -749,6 +751,48 @@ private:
|
|||
}
|
||||
|
||||
|
||||
void forwhile9()
|
||||
{
|
||||
check("char *f()\n"
|
||||
"{\n"
|
||||
" char *a = 0;\n"
|
||||
" int i = 0;\n"
|
||||
" for( ;; )\n"
|
||||
" {\n"
|
||||
" if(i>=0)\n"
|
||||
" continue;\n"
|
||||
" a = realloc( a, i );\n"
|
||||
" if(i>=0)\n"
|
||||
" continue;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" return a;\n"
|
||||
"}\n", true);
|
||||
ASSERT_EQUALS(std::string(""), errout.str());
|
||||
}
|
||||
|
||||
|
||||
void forwhile10()
|
||||
{
|
||||
check("char *f()\n"
|
||||
"{\n"
|
||||
" char *a = 0;\n"
|
||||
" int i = 0;\n"
|
||||
" for( ;; )\n"
|
||||
" {\n"
|
||||
" if(i>=0)\n"
|
||||
" continue;\n"
|
||||
" a = realloc( a, i );\n"
|
||||
" if(i>=0)\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" return a;\n"
|
||||
"}\n", true);
|
||||
ASSERT_EQUALS(std::string("[test.cpp:11]: Memory leak: a\n"), errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue