diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 8146ba498..1b99c7f22 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -960,6 +960,28 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list 0 && Token::Match(tok2, "%var% (")) + { + bool use = false; + for (const Token *tok3 = tok2->tokAt(2); tok3; tok3 = tok3->next()) + { + if (tok3->str() == "(") + tok3 = tok3->link(); + else if (tok3->str() == ")") + break; + else if (Token::Match(tok3->previous(), "(|, %varid% ,|)", varid)) + { + use = true; + break; + } + } + if (use) + { + addtoken("use"); + addtoken(";"); + break; + } + } } if (Token::Match(tok, "if ( ! %varid% &&", varid)) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index f038f3620..bfe589d13 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -494,6 +494,7 @@ private: ASSERT_EQUALS(";;use;", getcode("char *s; s2 = s;", "s")); ASSERT_EQUALS(";;use;", getcode("char *s; s2 = s + 10;", "s")); ASSERT_EQUALS(";;use;", getcode("char *s; s2 = x + s;", "s")); + ASSERT_EQUALS(";;use;if{;}", getcode("char *s; if (foo(s)) ;", "s")); // return.. ASSERT_EQUALS(";;return;", getcode("char *s; return;", "s"));