diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index fb9cb6167..13e8f8dac 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -632,7 +632,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, // Handle scopes that might be noreturn if (allocation.status == VarInfo::NOALLOC && Token::simpleMatch(tok, ") ; }")) { - const std::string &functionName(tok->link()->previous()->str()); + const std::string functionName(mSettings->library.getFunctionName(tok->link()->previous())); bool unknown = false; if (mTokenizer->isScopeNoReturn(tok->tokAt(2), &unknown)) { if (!unknown) @@ -847,7 +847,7 @@ void CheckLeakAutoVar::changeAllocStatus(VarInfo *varInfo, const VarInfo::AllocI void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpeningPar, VarInfo *varInfo, const VarInfo::AllocInfo& allocation, const Library::AllocFunc* af) { // Ignore function call? - if (mSettings->library.isLeakIgnore(tokName->str())) + if (mSettings->library.isLeakIgnore(mSettings->library.getFunctionName(tokName))) return; if (mSettings->library.getReallocFuncInfo(tokName)) return; diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 310ea2059..1c8b1b914 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -214,6 +214,7 @@ private: TEST_CASE(smartPtrInContainer); // #8262 TEST_CASE(functionCallCastConfig); // #9652 + TEST_CASE(functionCallLeakIgnoreConfig); // #7923 } #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) @@ -2360,6 +2361,27 @@ private: "}", settingsFunctionCall); ASSERT_EQUALS("[test.cpp:5]: (information) --check-library: Function free_func() should have / configuration\n", errout.str()); } + + void functionCallLeakIgnoreConfig() { // #7923 + Settings settingsLeakIgnore = settings; + + const char xmldata[] = "\n" + "\n" + " \n" + " \n" + " false\n" + " \n" + " \n" + "\n"; + tinyxml2::XMLDocument doc; + doc.Parse(xmldata, sizeof(xmldata)); + settingsLeakIgnore.library.load(doc); + check("void f() {\n" + " double* a = new double[1024];\n" + " SomeClass::someMethod(a);\n" + "}\n", settingsLeakIgnore); + ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: a\n", errout.str()); + } }; REGISTER_TEST(TestLeakAutoVar)