From 2396073262604615a27739e9282e1cd2f58b41fb Mon Sep 17 00:00:00 2001 From: Pavel Roschin Date: Tue, 28 Jan 2014 17:30:36 +0400 Subject: [PATCH] CheckMemoryLeak: improve leak checking in function parameters --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 940a576d9..ac7fe7c97 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2726,7 +2726,7 @@ void CheckMemoryLeakNoVar::check() for (const Token *tok3 = tok2; tok3; tok3 = tok3->previous()) { if (tok3->str() == "(") { // Is it a function call.. - if (Token::Match(tok3->tokAt(-2), "[;{}] %var% (")) { + if (!Token::Match(tok3->tokAt(-2), "= %var% (")) { const std::string& functionName = tok3->strAt(-1); if (functionName == "delete" || functionName == "free" || diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 52b2dc3b3..6fbbfbd1d 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -5562,6 +5562,24 @@ private: " close(fd);\n" "}"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Allocation with strdup, mkstemp doesn't release it.\n", "", errout.str()); + + check("void f()\n" + "{\n" + " if(TRUE || strcmp(strdup(a), b));\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (error) Allocation with strdup, strcmp doesn't release it.\n", errout.str()); + + check("void f()\n" + "{\n" + " if(!strcmp(strdup(a), b) == 0);\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (error) Allocation with strdup, strcmp doesn't release it.\n", errout.str()); + + check("void f()\n" + "{\n" + " 42, strcmp(strdup(a), b);\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (error) Allocation with strdup, strcmp doesn't release it.\n", errout.str()); } void missingAssignment() {