Merge branch 'master' of github.com:danmar/cppcheck

This commit is contained in:
Kimmo Varis 2009-08-18 21:49:47 +03:00
commit 2ca5caab28
2 changed files with 25 additions and 1 deletions

View File

@ -148,7 +148,10 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok
if (! tok2) if (! tok2)
return No; 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; return Malloc;
// GTK memory reallocation.. // GTK memory reallocation..

View File

@ -209,6 +209,7 @@ private:
TEST_CASE(func13); TEST_CASE(func13);
TEST_CASE(func14); TEST_CASE(func14);
TEST_CASE(func15); TEST_CASE(func15);
TEST_CASE(func16);
TEST_CASE(allocfunc1); TEST_CASE(allocfunc1);
TEST_CASE(allocfunc2); TEST_CASE(allocfunc2);
@ -1519,6 +1520,26 @@ private:
ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: p\n", errout.str()); 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() void allocfunc1()