diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 178ea2cad..7bb66975d 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -1447,14 +1447,16 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass(const Token * if (tok->isName() || Token::Match(tok, "[;}]")) { if (_settings._showAll || !isclass(tok->tokAt(1))) - CheckMemoryLeak_ClassMembers_Variable(classname, tok->strAt(3)); + CheckMemoryLeak_ClassMembers_Variable(classname, tok->tokAt(3)); } } } } -void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const std::vector &classname, const char varname[]) +void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const std::vector &classname, const Token *tokVarname) { + const char *varname = tokVarname->strAt(0); + // Function pattern.. Check if member function std::ostringstream fpattern; for (unsigned int i = 0; i < classname.size(); i++) @@ -1560,7 +1562,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const std::vect if (Alloc != No && Dealloc == No) { - MemoryLeak(_tokenizer->tokens(), FullVariableName.str().c_str(), Alloc, true); + MemoryLeak(tokVarname, FullVariableName.str().c_str(), Alloc, true); } } diff --git a/src/checkmemoryleak.h b/src/checkmemoryleak.h index e4d374e55..f58f08e23 100644 --- a/src/checkmemoryleak.h +++ b/src/checkmemoryleak.h @@ -58,7 +58,7 @@ private: } }; - void CheckMemoryLeak_ClassMembers_Variable(const std::vector &classname, const char varname[]); + void CheckMemoryLeak_ClassMembers_Variable(const std::vector &classname, const Token *tokVarname); void CheckMemoryLeak_ClassMembers_ParseClass(const Token *tok1, std::vector &classname); void CheckMemoryLeak_ClassMembers(); void CheckMemoryLeak_InFunction(); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 50e1ec5c2..062233531 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -1327,7 +1327,7 @@ private: " delete [] str2;\n" "}\n", true); - ASSERT_EQUALS(std::string("[test.cpp:1]: (all) Memory leak: Fred::str1\n"), errout.str()); + ASSERT_EQUALS(std::string("[test.cpp:4]: (all) Memory leak: Fred::str1\n"), errout.str()); }