Fixed #2129 (Invalid dereference after release report)

This commit is contained in:
Daniel Marjamäki 2010-10-26 17:49:48 +02:00
parent 893f7fa347
commit 27235f27ae
2 changed files with 17 additions and 1 deletions

View File

@ -676,9 +676,18 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
return 0; return 0;
} }
// is the varid a parameter?
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next())
{
if (tok2->str() == "(" || tok2->str() == ")")
break;
if (tok2->varId() == varid)
return "use_"; return "use_";
} }
return 0;
}
if (noreturn.find(tok->str()) != noreturn.end()) if (noreturn.find(tok->str()) != noreturn.end())
return "exit"; return "exit";

View File

@ -2280,6 +2280,13 @@ private:
" strcpy(str, p);\n" " strcpy(str, p);\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str());
check("void foo(int x) {\n"
" char *str = malloc(10);\n"
" free(str);\n"
" assert(x);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }