Memory leak: Fixed false positives about deallocating pointer that has already been deallocated

This commit is contained in:
Daniel Marjamäki 2009-01-16 16:29:41 +00:00
parent f663d1da84
commit 666fc82011
2 changed files with 17 additions and 3 deletions

View File

@ -1166,7 +1166,9 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
tok2->str("use");
else if (tok2->str() == "&use2" || tok2->str() == "use_")
tok2->str(";");
else if (tok2->str() == "recursive" || tok2->str() == "dealloc_")
else if (tok2->str() == "recursive")
tok2->str("use");
else if (tok2->str() == "dealloc_")
tok2->str("dealloc");
else if (tok2->str() == "realloc")
{

View File

@ -167,7 +167,8 @@ private:
TEST_CASE(dealloc_use_6);
// free a free'd pointer
TEST_CASE(freefree);
TEST_CASE(freefree1);
TEST_CASE(freefree2);
}
@ -1591,7 +1592,7 @@ private:
}
void freefree()
void freefree1()
{
check("void foo()\n"
"{\n"
@ -1602,6 +1603,17 @@ private:
ASSERT_EQUALS(std::string("[test.cpp:5]: Deallocating a deallocated pointer\n"), errout.str());
}
void freefree2()
{
check("void foo()\n"
"{\n"
" FILE *fd = fopen(\"test.txt\", \"wb\");\n"
" fprintf(fd, \"test\");\n"
" fclose(fd);\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
};
REGISTER_TEST(TestMemleak)