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() {