Fixed #554 (resource leak false positive)

This commit is contained in:
Daniel Marjamäki 2009-08-04 21:34:14 +02:00
parent 706ba34a6d
commit 9e348ca739
2 changed files with 16 additions and 1 deletions

View File

@ -1241,7 +1241,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
}
// Reduce "alloc|dealloc|use ; exit ;" => "; exit ;"
if (Token::Match(tok2, "alloc|dealloc|use ; exit ;"))
if (Token::Match(tok2, "alloc|dealloc|use|callfunc ; exit ;"))
{
tok2->deleteThis();
done = false;

View File

@ -266,6 +266,7 @@ private:
TEST_CASE(exit2);
TEST_CASE(exit3);
TEST_CASE(exit4);
TEST_CASE(exit5);
TEST_CASE(stdstring);
TEST_CASE(strndup_function);
@ -2164,6 +2165,20 @@ private:
ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: p\n", errout.str());
}
void exit5()
{
check("void f()\n"
"{\n"
" char *p = malloc(100);\n"
" if (p)\n"
" {\n"
" xyz();\n"
" exit(0);\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void stdstring()