From 1bb7b01a068717f3e9a98445f4067767d6303bc9 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Wed, 3 Jun 2009 23:20:33 +0300 Subject: [PATCH] Fix ticket #352 (Memory leaks: Missed memory leak when "--all" is not given) http://apps.sourceforge.net/trac/cppcheck/ticket/352 Detect memory leaks without --all when there is "alloc ; assign callfunc ; --- src/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 21b56a754..f1359768c 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -1333,7 +1333,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c MemoryLeak(result->tokAt(3), varname, alloctype, all); } - else if ((result = Token::findmatch(tok, "alloc ; alloc|assign|return ;")) != NULL) + else if ((result = Token::findmatch(tok, "alloc ; alloc|assign|return callfunc| ;")) != NULL) { MemoryLeak(result->tokAt(2), varname, alloctype, all); } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index c677e93ba..dc83d4028 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -1993,6 +1993,14 @@ private: " }\n" "}\n"); ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: p\n", errout.str()); + + check("void foo()\n" + "{\n" + " int *p = new int[100];\n" + " p = g();\n" + " delete [] p;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str()); } void unknownFunction3()