Fixed #9679 (False positive: use this after free (lambda not executed directly))
This commit is contained in:
parent
cd13798b6c
commit
aa1bbf2e62
|
@ -2699,9 +2699,12 @@ bool CheckClass::checkThisUseAfterFreeRecursive(const Scope *classScope, const F
|
|||
} else if (isDestroyed && Token::Match(tok->previous(), "!!. %name%") && tok->variable() && tok->variable()->scope() == classScope && !tok->variable()->isStatic() && !tok->variable()->isArgument()) {
|
||||
thisUseAfterFree(selfPointer->nameToken(), *freeToken, tok);
|
||||
return true;
|
||||
} else if (*freeToken && Token::Match(tok, "return|throw"))
|
||||
} else if (*freeToken && Token::Match(tok, "return|throw")) {
|
||||
// TODO
|
||||
return tok->str() == "throw";
|
||||
} else if (tok->str() == "{" && tok->scope()->type == Scope::ScopeType::eLambda) {
|
||||
tok = tok->link();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -7306,6 +7306,22 @@ private:
|
|||
"\n"
|
||||
"C* C::instanceSingleton;");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Avoid false positive when pointer is deleted in lambda
|
||||
checkThisUseAfterFree("class C {\n"
|
||||
"public:\n"
|
||||
" void foo();\n"
|
||||
" void set() { p = this; }\n"
|
||||
" void dostuff() {}\n"
|
||||
" C* p;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void C::foo() {\n"
|
||||
" auto done = [this] () { delete p; };\n"
|
||||
" dostuff();\n"
|
||||
" done();\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue