Fix FP memleak (#4145)

This commit is contained in:
chrchr-github 2022-05-30 06:55:15 +02:00 committed by GitHub
parent d7c914bd3e
commit 423e67bd6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -835,9 +835,13 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Variable * const var
if (getAllocationType(assignToks.second, assignToks.first->varId()) == AllocType::No)
continue;
if (variable->isArgument() && variable->valueType() && variable->valueType()->type == ValueType::UNKNOWN_TYPE &&
Token::simpleMatch(assignToks.first->astParent(), ".") && assignToks.first->astParent()->originalName() == "->")
continue;
if (variable->isArgument() && variable->valueType() && variable->valueType()->type == ValueType::UNKNOWN_TYPE && assignToks.first->astParent()) {
const Token* accessTok = assignToks.first->astParent();
while (Token::simpleMatch(accessTok->astOperand1(), "."))
accessTok = accessTok->astOperand1();
if (Token::simpleMatch(accessTok, ".") && accessTok->originalName() == "->")
continue;
}
const int structid(variable->declarationId());
const int structmemberid(assignToks.first->varId());

View File

@ -1949,6 +1949,8 @@ private:
check("void f(type_t t) {\n"
" t->p = malloc(10);\n"
" t->x.p = malloc(10);\n"
" t->y[2].p = malloc(10);\n"
"}\n", false);
ASSERT_EQUALS("", errout.str());
}