Skip to content

Commit

Permalink
Fix #9658 FP doubleFree after non-returning function pointer (#6590)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jul 13, 2024
1 parent 7aa5e4a commit 9b9a4b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,8 @@ bool Library::isnoreturn(const Token *ftok) const
{
if (ftok->function() && ftok->function()->isAttributeNoreturn())
return true;
if (ftok->variable() && ftok->variable()->nameToken()->isAttributeNoreturn())
return true;
if (isNotLibraryFunction(ftok)) {
if (Token::simpleMatch(ftok->astParent(), ".")) {
const Token* contTok = ftok->astParent()->astOperand1();
Expand Down
14 changes: 14 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class TestLeakAutoVar : public TestFixture {
TEST_CASE(exit1);
TEST_CASE(exit2);
TEST_CASE(exit3);
TEST_CASE(exit4);

// handling function calls
TEST_CASE(functioncall1);
Expand Down Expand Up @@ -1784,6 +1785,19 @@ class TestLeakAutoVar : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void exit4() {
check("void __attribute__((__noreturn__)) (*func_notret)(void);\n"
"int main(int argc) {\n"
" void* ptr = malloc(1000);\n"
" if (argc == 1) {\n"
" free(ptr);\n"
" func_notret();\n"
" }\n"
" free(ptr);\n"
"}");
ASSERT_EQUALS("", errout_str());
}

void functioncall1() {
check("void f(struct S *p) {\n"
" p->x = malloc(10);\n"
Expand Down

1 comment on commit 9b9a4b8

@danmar
Copy link
Owner

@danmar danmar commented on 9b9a4b8 Jul 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the sonar failure. I just wanted to look at the sonar results I did not intend to fail our CI. It seems to be too noisy for us. I have tried to remove the Sonar scan.

Please sign in to comment.