diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index c5e7bd436..4a0e3c1c6 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -676,7 +676,16 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::listtokAt(2); tok2; tok2 = tok2->next()) + { + if (tok2->str() == "(" || tok2->str() == ")") + break; + if (tok2->varId() == varid) + return "use_"; + } + + return 0; } if (noreturn.find(tok->str()) != noreturn.end()) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 0834dff15..f8293f5d2 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2280,6 +2280,13 @@ private: " strcpy(str, p);\n" "}\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str()); + + check("void foo(int x) {\n" + " char *str = malloc(10);\n" + " free(str);\n" + " assert(x);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); }