diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 88166a7bf..559562d5c 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -523,6 +523,8 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::listprevious()->str() == "."); + for (; tok; tok = tok->next()) { if (tok->str() == "(") @@ -542,6 +544,9 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list 0 && Token::Match(tok, "[,()] %varid% [,()]", varid)) { + if (dot) + return "use"; + const Token *ftok = _tokenizer->getFunctionTokenByName(funcname.c_str()); if (!ftok) return "use"; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index e65732205..ac6307935 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -271,6 +271,8 @@ private: // Unknown syntax TEST_CASE(unknownSyntax1); TEST_CASE(knownFunctions); + + TEST_CASE(same_function_name); } @@ -2393,6 +2395,18 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str()); } + + void same_function_name() + { + check("void a(char *p)\n" + "{ }\n" + "void b()\n" + "{\n" + " char *p = malloc(10);\n" + " abc.a(p);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } }; static TestMemleakInFunction testMemleakInFunction;