From 5692e7a6f6f6608b68f6ee4b58a142d669d91945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 24 May 2010 19:28:27 +0200 Subject: [PATCH] Fixed #1707 (false positive: Memory leak) --- lib/checkmemoryleak.cpp | 22 ++++++++++++++++++++++ test/testmemleak.cpp | 1 + 2 files changed, 23 insertions(+) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 8146ba498..1b99c7f22 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -960,6 +960,28 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list 0 && Token::Match(tok2, "%var% (")) + { + bool use = false; + for (const Token *tok3 = tok2->tokAt(2); tok3; tok3 = tok3->next()) + { + if (tok3->str() == "(") + tok3 = tok3->link(); + else if (tok3->str() == ")") + break; + else if (Token::Match(tok3->previous(), "(|, %varid% ,|)", varid)) + { + use = true; + break; + } + } + if (use) + { + addtoken("use"); + addtoken(";"); + break; + } + } } if (Token::Match(tok, "if ( ! %varid% &&", varid)) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index f038f3620..bfe589d13 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -494,6 +494,7 @@ private: ASSERT_EQUALS(";;use;", getcode("char *s; s2 = s;", "s")); ASSERT_EQUALS(";;use;", getcode("char *s; s2 = s + 10;", "s")); ASSERT_EQUALS(";;use;", getcode("char *s; s2 = x + s;", "s")); + ASSERT_EQUALS(";;use;if{;}", getcode("char *s; if (foo(s)) ;", "s")); // return.. ASSERT_EQUALS(";;return;", getcode("char *s; return;", "s"));