diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 8f2b9c6ae..6e639246f 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -160,7 +160,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, if (tok->varId() > 0) { const std::map::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()); diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index c0c4adf37..4089baa7a 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -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