From b3ad712b6174a57963d3807ff03b9baeae27aedc Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Thu, 1 Oct 2009 11:56:59 +0300 Subject: [PATCH] Fix #421 (Memory leak not found when typeid() is used.) http://sourceforge.net/apps/trac/cppcheck/ticket/421 --- src/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 94b43db5b..b86a98ef8 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -52,7 +52,7 @@ static const char * const call_func_white_list[] = , "setbuf", "setbuffer", "setlinebuf", "setvbuf", "snprintf", "sprintf", "strcasecmp" , "strcat", "strchr", "strcmp", "strcpy", "stricmp", "strncat", "strncmp" , "strncpy", "strrchr", "strstr", "strtod", "strtol", "strtoul", "switch" - , "sync_file_range", "telldir", "while", "write", "writev" + , "sync_file_range", "telldir", "typeid", "while", "write", "writev" }; static int call_func_white_list_compare(const void *a, const void *b) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index e22591f3f..540f4fb75 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -269,6 +269,7 @@ private: // Unknown syntax TEST_CASE(unknownSyntax1); + TEST_CASE(knownFunctions); } @@ -2324,6 +2325,16 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); } + + void knownFunctions() + { + check("void foo()\n" + "{\n" + " int *p = new int[100];\n" + " typeid(p);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str()); + } }; static TestMemleakInFunction testMemleakInFunction;