Fixed #3891 (False positive 'Double deallocation:' due to ((void*)1))

This commit is contained in:
Daniel Marjamäki 2012-07-16 17:07:51 +02:00
parent 2103811291
commit ddfc968028
2 changed files with 14 additions and 3 deletions

View File

@ -422,7 +422,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
}
// Function call..
else if (Token::Match(tok, "%type% (")) {
else if (Token::Match(tok, "%type% (") && tok->str() != "return") {
std::string dealloc;
{
const std::map<std::string, std::string>::iterator func = deallocFunctions.find(tok->str());

View File

@ -49,7 +49,8 @@ private:
TEST_CASE(deallocuse3);
TEST_CASE(deallocuse4);
TEST_CASE(doublefree);
TEST_CASE(doublefree1);
TEST_CASE(doublefree2);
// exit
TEST_CASE(exit1);
@ -242,7 +243,7 @@ private:
ASSERT_EQUALS("[test.c:3]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", errout.str());
}
void doublefree() { // #3895
void doublefree1() { // #3895
check("void f(char *p) {\n"
" if (x)\n"
" free(p);\n"
@ -253,6 +254,16 @@ private:
ASSERT_EQUALS("[test.c:6]: (error) Memory pointed to by 'p' is freed twice.\n", errout.str());
}
void doublefree2() { // #3891
check("void *f(int a) {\n"
" char *p = malloc(10);\n"
" if (a == 2) { free(p); return ((void*)1); }\n"
" free(p);\n"
" return 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void exit1() {
check("void f() {\n"
" char *p = malloc(10);\n"