Skip to content

Commit

Permalink
Fix #13311 FP thisUseAfterFree with static instance pointer (#7008)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 5, 2024
1 parent 0003ad2 commit 30ab5f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3470,7 +3470,7 @@ bool CheckClass::checkThisUseAfterFreeRecursive(const Scope *classScope, const F
tok = tok->tokAt(2);
} else if (Token::Match(tok, "%var% . reset ( )") && selfPointer == tok->variable())
freeToken = tok;
else if (Token::Match(tok->previous(), "!!. %name% (") && tok->function() && tok->function()->nestedIn == classScope) {
else if (Token::Match(tok->previous(), "!!. %name% (") && tok->function() && tok->function()->nestedIn == classScope && tok->function()->type == Function::eFunction) {
if (isDestroyed) {
thisUseAfterFree(selfPointer->nameToken(), freeToken, tok);
return true;
Expand Down
16 changes: 16 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8947,6 +8947,22 @@ class TestClass : public TestFixture {
" done();\n"
"}");
ASSERT_EQUALS("", errout_str());

checkThisUseAfterFree("class C {\n" // #13311
"public:\n"
" static void init();\n"
"private:\n"
" C();\n"
" static C* self;\n"
" bool use;\n"
"};\n"
"C::C() { use = true; }\n"
"void C::init() {\n"
" if (self)\n"
" delete self;\n"
" self = new C();\n"
"}");
ASSERT_EQUALS("", errout_str());
}


Expand Down

0 comments on commit 30ab5f3

Please sign in to comment.