Using freed memory : Fixed false positive when usage is something like: printf("free %x",p);

This commit is contained in:
Daniel Marjamäki 2009-01-03 07:47:35 +00:00
parent b756158644
commit 2b3a987552
2 changed files with 13 additions and 1 deletions

View File

@ -245,7 +245,7 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list<const
const TOKEN *ftok = _tokenizer->GetFunctionTokenByName(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();

View File

@ -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 )