diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 16a4a89b9..4df223d69 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -422,7 +422,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, } // Function call.. - else if (Token::Match(tok, "%type% (")) { + else if (Token::Match(tok, "%type% (") && tok->str() != "return") { std::string dealloc; { const std::map::iterator func = deallocFunctions.find(tok->str()); diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 3b6af9306..b45c38720 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -49,7 +49,8 @@ private: TEST_CASE(deallocuse3); TEST_CASE(deallocuse4); - TEST_CASE(doublefree); + TEST_CASE(doublefree1); + TEST_CASE(doublefree2); // exit TEST_CASE(exit1); @@ -242,7 +243,7 @@ private: ASSERT_EQUALS("[test.c:3]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", errout.str()); } - void doublefree() { // #3895 + void doublefree1() { // #3895 check("void f(char *p) {\n" " if (x)\n" " free(p);\n" @@ -253,6 +254,16 @@ private: ASSERT_EQUALS("[test.c:6]: (error) Memory pointed to by 'p' is freed twice.\n", errout.str()); } + void doublefree2() { // #3891 + check("void *f(int a) {\n" + " char *p = malloc(10);\n" + " if (a == 2) { free(p); return ((void*)1); }\n" + " free(p);\n" + " return 0;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void exit1() { check("void f() {\n" " char *p = malloc(10);\n"