diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index 07ddd6bd0..d417407e7 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -169,7 +169,10 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[] } // Used.. - if ( Match( tok, "[=,(] %var1%", varnames ) ) + // list.push_back( var1 ); + // listtail->next = var1; + // foo( var1 ); + if ( Match( tok, "[=,(] %var1% [,);]", varnames ) ) return; if ( Match( tok, "return %var1%", varnames ) ) return; diff --git a/tests.cpp b/tests.cpp index c34b71b31..8bef178cb 100644 --- a/tests.cpp +++ b/tests.cpp @@ -564,6 +564,27 @@ static void memleak_in_function() "}\n"; check( CheckMemoryLeak, __LINE__, test10, "[test.cpp:3]: Memory leak: obj_list\n" ); + + + const char test11[] = "static char *f()\n" + "{\n" + " char *s = new char[100];\n" + " return s;\n" + "}\n"; + check( CheckMemoryLeak, __LINE__, test11, "" ); + + + + + const char test12[] = "static char *f()\n" + "{\n" + " Fred *fred = new Fred;\n" + " free( fred->Name );\n" + "}\n"; + check( CheckMemoryLeak, __LINE__, test12, "[test.cpp:3]: Memory leak: fred\n" ); + + + } //---------------------------------------------------------------------------