checkmemoryleak: no longer flag "dealloc ; alloc ; if continue ;" as a leak, even with --all

This commit is contained in:
Leandro Penz 2009-01-10 16:28:04 +00:00
parent 1a4cfc6c4f
commit 5570f06075
2 changed files with 46 additions and 1 deletions

View File

@ -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);
}

View File

@ -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());
}