Fixed a false positive (memory leak)

This false positive was first discovered in the VLC sourcecode. The TestMemoryLeakInFunction::simple11 test case is a simplified test code of that code.
This commit is contained in:
Daniel Marjamäki 2009-06-17 21:42:49 +02:00
parent 071c79c5cb
commit 5d0d21d668
2 changed files with 25 additions and 8 deletions

View File

@ -1322,14 +1322,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
done = false;
}
// Reduce "if* alloc ; dealloc ;" => ";"
if (Token::simpleMatch(tok2->tokAt(2), "alloc ; dealloc ;") &&
tok2->next()->str().find("if") == 0)
{
Token::eraseTokens(tok2, tok2->tokAt(5));
done = false;
}
// Delete second use in "use ; use ;"
while (Token::Match(tok2, "[;{}] use ; use ;"))
{

View File

@ -128,6 +128,7 @@ private:
TEST_CASE(simple8);
TEST_CASE(simple9); // Bug 2435468 - member function "free"
TEST_CASE(simple10); // fclose in a if condition
TEST_CASE(simple11);
TEST_CASE(new_nothrow);
TEST_CASE(alloc_alloc_1);
@ -402,6 +403,30 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simple11()
{
check("void Fred::aaa()\n"
"{ }\n"
"\n"
"void Fred::foo()\n"
"{\n"
" char *s = NULL;\n"
" if (a)\n"
" s = malloc(10);\n"
" else if (b)\n"
" s = malloc(10);\n"
" else\n"
" f();\n"
" g(s);\n"
" if (c)\n"
" h(s);\n"
" free(s);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void new_nothrow()
{
check("void f()\n"