Skip to content

Commit 30ab5f3

Browse files
Fix #13311 FP thisUseAfterFree with static instance pointer (danmar#7008)
1 parent 0003ad2 commit 30ab5f3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3470,7 +3470,7 @@ bool CheckClass::checkThisUseAfterFreeRecursive(const Scope *classScope, const F
34703470
tok = tok->tokAt(2);
34713471
} else if (Token::Match(tok, "%var% . reset ( )") && selfPointer == tok->variable())
34723472
freeToken = tok;
3473-
else if (Token::Match(tok->previous(), "!!. %name% (") && tok->function() && tok->function()->nestedIn == classScope) {
3473+
else if (Token::Match(tok->previous(), "!!. %name% (") && tok->function() && tok->function()->nestedIn == classScope && tok->function()->type == Function::eFunction) {
34743474
if (isDestroyed) {
34753475
thisUseAfterFree(selfPointer->nameToken(), freeToken, tok);
34763476
return true;

test/testclass.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8947,6 +8947,22 @@ class TestClass : public TestFixture {
89478947
" done();\n"
89488948
"}");
89498949
ASSERT_EQUALS("", errout_str());
8950+
8951+
checkThisUseAfterFree("class C {\n" // #13311
8952+
"public:\n"
8953+
" static void init();\n"
8954+
"private:\n"
8955+
" C();\n"
8956+
" static C* self;\n"
8957+
" bool use;\n"
8958+
"};\n"
8959+
"C::C() { use = true; }\n"
8960+
"void C::init() {\n"
8961+
" if (self)\n"
8962+
" delete self;\n"
8963+
" self = new C();\n"
8964+
"}");
8965+
ASSERT_EQUALS("", errout_str());
89508966
}
89518967

89528968

0 commit comments

Comments
 (0)