diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index a756e0693..a0ffc1eaf 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1000,7 +1000,7 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope) functionName == "free" || functionName == "fclose" || functionName == "realloc") - break; + continue; if (!CheckMemoryLeakInFunction::test_white_list(functionName, mSettings, mTokenizer->isCPP())) continue; @@ -1016,7 +1016,6 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope) if (isReopenStandardStream(arg)) continue; functionCallLeak(arg, arg->str(), functionName); - break; } } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index c4554d28e..17342d1ea 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2159,6 +2159,18 @@ private: " return ret;\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" + " free(malloc(1));\n" + " strcpy(a, strdup(p));\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (error) Allocation with strdup, strcpy doesn't release it.\n", errout.str()); + + check("void f() {\n" + " memcmp(calloc(10, 10), strdup(q), 100);\n" + "}"); + 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()); } void missingAssignment() {