From a82b46dad617502e8c81528b79f1b6a15be5b98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 21 Nov 2008 18:02:20 +0000 Subject: [PATCH] Memory leak: Better handling when calling functions --- CheckMemoryLeak.cpp | 6 +++--- testmemleak.cpp | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index 90ddafbc7..8476ab3a0 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -180,13 +180,13 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list 2 ) - return 0; + return "dealloc"; const char *funcname = tok->str; for ( std::list::const_iterator it = callstack.begin(); it != callstack.end(); ++it ) { if ( std::string(funcname) == (*it)->str ) - return 0; + return "dealloc"; } callstack.push_back(tok); @@ -220,7 +220,7 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list [test.cpp:3]: Mismatching allocation and deallocation: str\n"), err ); } + + void func6() + { + check( "static void foo(char *str)\n" + "{\n" + " goto abc;\n" + "}\n" + "\n" + "static void f()\n" + "{\n" + " char *p = new char[100];\n" + " foo(p);\n" + "}\n" ); + std::string err( errout.str() ); + ASSERT_EQUALS( std::string(""), err ); + } + /*