From 0081800a20d03a4b99cc859c538238233df450db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 30 Nov 2010 19:36:04 +0100 Subject: [PATCH] Fixed #2261 (False positive: memory leak) --- lib/checkmemoryleak.cpp | 10 ++++++++++ test/testmemleak.cpp | 1 + 2 files changed, 11 insertions(+) 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"));