diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 8de152325..4ee8c7ba2 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1518,6 +1518,16 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listnext()) + { + if (Token::simpleMatch(tok1, "callfunc alloc ;")) + { + tok1->deleteThis(); + tok1->insertToken("use"); + tok1->insertToken(";"); + } + } + return rethead; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index d49731f8f..f70273365 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -535,6 +535,7 @@ private: 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")); + ASSERT_EQUALS(";;alloc;use;", getcode("Fred *fred; p.setFred(fred = new Fred);", "fred")); // non-use.. ASSERT_EQUALS(";;", getcode("char *s; s = s + 1;", "s"));