Fixed #591 (False positive: Deallocating a deallocated pointer)

This commit is contained in:
Daniel Marjamäki 2009-08-18 20:49:08 +02:00
parent 23ac70b8b3
commit 85682ed429
2 changed files with 25 additions and 1 deletions

View File

@ -148,7 +148,10 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok
if (! tok2)
return No;
if (Token::Match(tok2, (std::string("realloc ( ") + varname).c_str()))
if (! Token::Match(tok2, (std::string("%var% ( ") + varname + " [,)]").c_str()))
return No;
if (tok2->str() == "realloc")
return Malloc;
// GTK memory reallocation..

View File

@ -209,6 +209,7 @@ private:
TEST_CASE(func13);
TEST_CASE(func14);
TEST_CASE(func15);
TEST_CASE(func16);
TEST_CASE(allocfunc1);
TEST_CASE(allocfunc2);
@ -1519,6 +1520,26 @@ private:
ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: p\n", errout.str());
}
void func16()
{
check("static void a( bo_t *p_bo)\n"
"{\n"
" p_bo->buffer = realloc( p_bo->buffer, 100 );\n"
"}\n"
"\n"
"static bo_t * b()\n"
"{\n"
" bo_t *box;\n"
" if( ( box = malloc( sizeof( bo_t ) ) ) )\n"
" {\n"
" a(box);\n"
" a(box);\n"
" }\n"
" return box;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void allocfunc1()