Ticket #6648: Properly handle variables that have been deallocated and whose _address_ is taken after in CheckLeakAutoVar.

This commit is contained in:
Simon Martin 2015-07-19 17:37:50 +02:00
parent f1f46611d6
commit fa94f2e0f4
2 changed files with 9 additions and 2 deletions

View File

@ -160,7 +160,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
if (tok->varId() > 0) {
const std::map<unsigned int, VarInfo::AllocInfo>::const_iterator var = alloctype.find(tok->varId());
if (var != alloctype.end()) {
if (var->second.status == VarInfo::DEALLOC && (!Token::Match(tok, "%name% =") || tok->strAt(-1) == "*")) {
if (var->second.status == VarInfo::DEALLOC && tok->strAt(-1) != "&" && (!Token::Match(tok, "%name% =") || tok->strAt(-1) == "*")) {
deallocUseError(tok, tok->str());
} else if (Token::simpleMatch(tok->tokAt(-2), "= &")) {
varInfo->erase(tok->varId());

View File

@ -314,7 +314,7 @@ private:
ASSERT_EQUALS("", errout.str());
}
void deallocuse7() { // #6467, #6469, #6473
void deallocuse7() { // #6467, #6469, #6473, #6648
check("struct Foo { int* ptr; };\n"
"void f(Foo* foo) {\n"
" delete foo->ptr;\n"
@ -349,6 +349,13 @@ private:
" foo->ptr->func();\n"
"}", true);
ASSERT_EQUALS("", errout.str());
check("void foo(void (*conv)(char**)) {\n"
" char * ptr=(char*)malloc(42);\n"
" free(ptr);\n"
" (*conv)(&ptr);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void doublefree1() { // #3895