diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index a8fbe2b9a..e20f3f102 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1264,12 +1264,6 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listnext(); tok2; tok2 = tok2->next()) { if (tok2->str() == ";") - break; - - if (tok2->varId() == varid) { - addtoken("use"); tok = tok2; break; } + + if (tok2->varId() == varid) + { + // Read data.. + if (!Token::Match(tok2->previous(), "&|(") && + Token::simpleMatch(tok2->next(), "[")) + { + } + else + { + use = true; + } + } } + if (use) + addtoken("use"); + addtoken(";"); } } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 2b2c6180f..6303776e7 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -524,6 +524,7 @@ private: // return.. ASSERT_EQUALS(";;return;", getcode("char *s; return;", "s")); ASSERT_EQUALS(";;returnuse;", getcode("char *s; return s;", "s")); + ASSERT_EQUALS(";;return;", getcode("char *s; return 5 + s[0];", "s")); // assign.. ASSERT_EQUALS(";;assign;", getcode("char *s; s = 0;", "s"));