Skip to content

Commit

Permalink
Fix FN deallocuse with function call (refs #11409)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jan 3, 2024
1 parent dd869cf commit 82ffa7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,8 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
const VarInfo::AllocInfo sp_allocation(sp_af ? sp_af->groupId : (arrayDelete ? NEW_ARRAY : NEW), VarInfo::OWNED, allocTok);
changeAllocStatus(varInfo, sp_allocation, vtok, vtok);
} else {
while (arg->isUnaryOp("*") || arg->isUnaryOp("&"))
arg = arg->astOperand1();
checkTokenInsideExpression(arg, varInfo);
}
// TODO: check each token in argument expression (could contain multiple variables)
Expand Down
8 changes: 8 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,14 @@ class TestLeakAutoVar : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.c:4]: (error) Dereferencing 'p' after it is deallocated / released\n",
errout.str());

check("void g(int);\n"
"void f(int* p) {\n"
" free(p);\n"
" g(*p);\n"
"}\n");
ASSERT_EQUALS("[test.c:4]: (error) Dereferencing 'p' after it is deallocated / released\n",
errout.str());
}

void doublefree1() { // #3895
Expand Down

0 comments on commit 82ffa7b

Please sign in to comment.