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

This commit is contained in:
Kimmo Varis 2010-09-11 12:20:40 +03:00
commit 77126f0b0b
2 changed files with 14 additions and 1 deletions

View File

@ -2275,7 +2275,8 @@ void CheckMemoryLeakInFunction::checkReallocUsage()
parameterVarIds.find(tok->varId()) == parameterVarIds.end())
{
// Check that another copy of the pointer wasn't saved earlier in the function
if (!Token::findmatch(startOfFunction, "%var% = %varid% ;", tok->varId()))
if (!Token::findmatch(startOfFunction, "%var% = %varid% ;", tok->varId()) &&
!Token::findmatch(startOfFunction, "[{};] %varid% = %var% [;=]", tok->varId()))
memleakUponReallocFailureError(tok, tok->str());
}
}

View File

@ -334,6 +334,7 @@ private:
TEST_CASE(realloc7);
TEST_CASE(realloc8);
TEST_CASE(realloc9);
TEST_CASE(realloc10);
TEST_CASE(assign);
@ -2077,6 +2078,17 @@ private:
ASSERT_EQUALS("", errout.str());
}
void realloc10()
{
check("void foo() {\n"
" char *pa, *pb;\n"
" pa = pb = malloc(10);\n"
" pa = realloc(pa, 20);"
" exit();\n"
"}\n", false);
ASSERT_EQUALS("", errout.str());
}
void assign()
{
check("void foo()\n"