From 239b660a52f5b3747bbfd47153b67a8d87a4371c Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Wed, 30 Oct 2019 17:55:47 +0100 Subject: [PATCH] Fix #9438 (Don't warn for return (void*) malloc(1)) (#2307) --- lib/checkmemoryleak.cpp | 3 ++- test/testmemleak.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index a0ffc1eaf..1b7a4cdd5 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -999,7 +999,8 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope) if ((mTokenizer->isCPP() && functionName == "delete") || functionName == "free" || functionName == "fclose" || - functionName == "realloc") + functionName == "realloc" || + functionName == "return") continue; if (!CheckMemoryLeakInFunction::test_white_list(functionName, mSettings, mTokenizer->isCPP())) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 4467691f7..8af889b49 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2171,6 +2171,16 @@ private: "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Allocation with calloc, memcmp doesn't release it.\n" "[test.cpp:2]: (error) Allocation with strdup, memcmp doesn't release it.\n", errout.str()); + + check("void* f(int size) {\n" + " return (void*) malloc(size);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check("int* f(int size) {\n" + " return static_cast(malloc(size));\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void missingAssignment() {