From 2b3a987552903ed5ca25b71b94e4591191c2a7b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 3 Jan 2009 07:47:35 +0000 Subject: [PATCH] Using freed memory : Fixed false positive when usage is something like: printf("free %x",p); --- checkmemoryleak.cpp | 2 +- testmemleak.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/checkmemoryleak.cpp b/checkmemoryleak.cpp index 38ffb0e5c..0abee772b 100644 --- a/checkmemoryleak.cpp +++ b/checkmemoryleak.cpp @@ -245,7 +245,7 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::listGetFunctionTokenByName(funcname); const char *parname = Tokenizer::getParameterName( ftok, par ); if ( ! parname ) - return "use"; + return "recursive"; // Check if the function deallocates the variable.. while ( ftok && (ftok->str() != "{") ) ftok = ftok->next(); diff --git a/testmemleak.cpp b/testmemleak.cpp index c43e74339..a491268aa 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -159,6 +159,7 @@ private: TEST_CASE( dealloc_use_3 ); // Deallocate and then use memory. No error TEST_CASE( dealloc_use_4 ); TEST_CASE( dealloc_use_5 ); + TEST_CASE( dealloc_use_6 ); } @@ -1470,6 +1471,17 @@ private: ASSERT_EQUALS( std::string("[test.cpp:5]: Using \"str\" after it has been deallocated / released\n"), errout.str() ); } + void dealloc_use_6() + { + check( "void foo()\n" + "{\n" + " char *str = 0;\n" + " free(str);\n" + " printf(\"free %x\", str);\n" + "}\n" ); + ASSERT_EQUALS( std::string(""), errout.str() ); + } + }; REGISTER_TEST( TestMemleak )