diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 362b3fa44..ff455e8fa 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1311,6 +1311,36 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listnext()) + { + if (tok2->str() == "{") + ++indentlevel2; + else if (tok2->str() == "}") + { + if (indentlevel2 <= 1) + break; + --indentlevel2; + } + else if (tok2->varId() == varid) + { + use = true; + break; + } + } + + if (use) + { + addtoken(&rettail, tok, "use"); + addtoken(&rettail, tok, ";"); + tok = tok->next()->link(); + continue; + } + } + if (Token::Match(tok, "[)=] %varid% [+;)]", varid) || Token::Match(tok, "%var% + %varid%", varid) || Token::Match(tok, "%varid% +=|-=", varid) || diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 8557a602b..23596bce2 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -530,6 +530,7 @@ private: ASSERT_EQUALS(";;use;if{;}", getcode("char *s; if (foo(s)) ;", "s")); ASSERT_EQUALS(";;use;", getcode("char *s; map1[s] = 0;", "s")); ASSERT_EQUALS(";;;;", getcode("char *p; const char *q; q = p;", "p")); + ASSERT_EQUALS(";;use;;", getcode("char *s; x = {1,s};", "s")); // return.. ASSERT_EQUALS(";;return;", getcode("char *s; return;", "s"));