Fixed #2023 (false positive with realloc())
This commit is contained in:
parent
69afc0a0db
commit
ecd863700e
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue