From 01a0154daa625e5e3dd9f4eb1023743050603ca8 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 21 May 2014 13:45:36 +0200 Subject: [PATCH] Fixed false positive #5848 --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 1c4dd2187..f79ad8f38 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2762,7 +2762,7 @@ void CheckMemoryLeakNoVar::check() void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope) { for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { - if (Token::Match(tok, "{|}|; %var% (")) { + if (Token::Match(tok, "{|}|; %var% (") && tok->strAt(-1) != "=") { tok = tok->next(); const int allocationId = _settings->library.alloc(tok); if (allocationId > 0) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 3c83d1420..d0ef25b6c 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -6345,6 +6345,12 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + check("char** x(const char* str) {\n" + " char* ptr[] = { malloc(10), malloc(5), strdup(str) };\n" + " return ptr;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void x()\n" "{\n" " 42,malloc(42);\n"