Skip to content

Commit 9b9a4b8

Browse files
Fix #9658 FP doubleFree after non-returning function pointer (#6590)
1 parent 7aa5e4a commit 9b9a4b8

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/library.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,8 @@ bool Library::isnoreturn(const Token *ftok) const
17151715
{
17161716
if (ftok->function() && ftok->function()->isAttributeNoreturn())
17171717
return true;
1718+
if (ftok->variable() && ftok->variable()->nameToken()->isAttributeNoreturn())
1719+
return true;
17181720
if (isNotLibraryFunction(ftok)) {
17191721
if (Token::simpleMatch(ftok->astParent(), ".")) {
17201722
const Token* contTok = ftok->astParent()->astOperand1();

test/testleakautovar.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class TestLeakAutoVar : public TestFixture {
131131
TEST_CASE(exit1);
132132
TEST_CASE(exit2);
133133
TEST_CASE(exit3);
134+
TEST_CASE(exit4);
134135

135136
// handling function calls
136137
TEST_CASE(functioncall1);
@@ -1784,6 +1785,19 @@ class TestLeakAutoVar : public TestFixture {
17841785
ASSERT_EQUALS("", errout_str());
17851786
}
17861787

1788+
void exit4() {
1789+
check("void __attribute__((__noreturn__)) (*func_notret)(void);\n"
1790+
"int main(int argc) {\n"
1791+
" void* ptr = malloc(1000);\n"
1792+
" if (argc == 1) {\n"
1793+
" free(ptr);\n"
1794+
" func_notret();\n"
1795+
" }\n"
1796+
" free(ptr);\n"
1797+
"}");
1798+
ASSERT_EQUALS("", errout_str());
1799+
}
1800+
17871801
void functioncall1() {
17881802
check("void f(struct S *p) {\n"
17891803
" p->x = malloc(10);\n"

0 commit comments

Comments
 (0)