diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 631a52dcc..1fdd7e1f4 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1382,21 +1382,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listtokAt(-2), "; %var% = %varid%", varid)) - { - const unsigned int varid2(tok->previous()->varId()); - if (Token::Match(tok->tokAt(-6), "const %type% * %varid% ;", varid2) || - Token::Match(tok->tokAt(-7), "const struct %type% * %varid% ;", varid2)) - { - // address is taken by pointer constant - used = false; - } - } - - if (used) - addtoken(&rettail, tok, "use"); + addtoken(&rettail, tok, "use"); } else if (Token::Match(tok->previous(), "[;{}=(,+-*/] %varid% [", varid)) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 8dc80ed52..065923eb1 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -531,8 +531,9 @@ private: ASSERT_EQUALS(";;use;", getcode("char *s; s2 = x + s;", "s")); 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 *p; const char *q; q = p;", "p")); ASSERT_EQUALS(";;use;;", getcode("char *s; x = {1,s};", "s")); + ASSERT_EQUALS(";{};;alloc;;use;", getcode("struct Foo { }; Foo *p; p = malloc(10); const Foo *q; q = p;", "p")); // non-use.. ASSERT_EQUALS(";;", getcode("char *s; s = s + 1;", "s"));