diff --git a/checkmemoryleak.cpp b/checkmemoryleak.cpp index 059a381f0..8f93caa9a 100644 --- a/checkmemoryleak.cpp +++ b/checkmemoryleak.cpp @@ -549,6 +549,20 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list if ( TOKEN::Match(tok, "return %var1%", varnames) || TOKEN::Match(tok, "return & %var1%", varnames) ) addtoken("use"); + if (TOKEN::simpleMatch(tok->next(), "(")) + { + for (const TOKEN *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next() ) + { + if ( tok2->str() == "(" || tok2->str() == ")" ) + break; + + if ( tok2->str() == varname ) + { + addtoken("use"); + break; + } + } + } } // throw.. diff --git a/testmemleak.cpp b/testmemleak.cpp index 842c945a2..816daf7ec 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -111,6 +111,7 @@ private: TEST_CASE( ret2 ); TEST_CASE( ret3 ); TEST_CASE( ret4 ); + TEST_CASE( ret5 ); // Bug 2458436 - return use TEST_CASE( mismatch1 ); @@ -818,6 +819,19 @@ private: ASSERT_EQUALS( std::string("[test.cpp:4]: Resource leak: p\n"), errout.str() ); } + void ret5() + { + check( "static char * f()\n" + "{\n" + " char *c = new char[50];\n" + " return (c ? c : NULL);\n" + "}\n" ); + ASSERT_EQUALS( std::string(""), errout.str() ); + } + + + + void mismatch1() { check( "void f()\n"