From 7eb398841579caec4db693f86f13ad3c5b1a24fd Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 11 Apr 2014 05:40:37 +0200 Subject: [PATCH] Fixed #5659 (False negative: mismatching allocation / deallocation whith using namespace) --- lib/symboldatabase.cpp | 13 ++++++++++++- test/testmemleak.cpp | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 28c55e997..983069467 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3038,7 +3038,18 @@ const Scope * SymbolDatabase::findNamespace(const Token * tok, const Scope * sco Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *ns) { - const Function * function = ns->findFunction(func); + const Function * function = nullptr; + + std::list::const_iterator it; + + for (it = ns->functionList.begin(); it != ns->functionList.end(); ++it) { + if (it->name() == func->str()) { + if (Function::argsMatch(ns, func->tokAt(2), it->argDef->next(), "", 0)) { + function = &*it; + break; + } + } + } if (!function) { const Scope * scope = ns->findRecordInNestedList(func->str()); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 379af287f..06d1a7e0e 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -5442,6 +5442,29 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:16]: (warning) Possible leak in public function. The pointer 'data_' is not deallocated before it is allocated.\n" "[test.cpp:18]: (error) Mismatching allocation and deallocation: Foo::data_\n", errout.str()); + + check("namespace NS\n" + "{\n" + "class Foo\n" + "{\n" + "public:\n" + " void fct(int i);\n" + "\n" + "private:\n" + " char* data_;\n" + "};\n" + "}\n" + "\n" + "using namespace NS;\n" + "\n" + "void Foo::fct(int i)\n" + "{\n" + " data_ = new char[42];\n" + " delete data_;\n" + " data_ = 0;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:16]: (warning) Possible leak in public function. The pointer 'data_' is not deallocated before it is allocated.\n" + "[test.cpp:18]: (error) Mismatching allocation and deallocation: Foo::data_\n", errout.str()); } void func1() {