Fix #10789 Crash in CheckMemoryLeakInClass (#3797)

This commit is contained in:
chrchr-github 2022-02-04 19:32:23 +01:00 committed by GitHub
parent 31ea13eb0c
commit 7f28edbe26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -579,6 +579,8 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
}
continue;
}
if (!func.functionScope) // defaulted destructor
continue;
bool body = false;
const Token *end = func.functionScope->bodyEnd;
for (const Token *tok = func.arg->link(); tok != end; tok = tok->next()) {

View File

@ -521,6 +521,7 @@ private:
TEST_CASE(class23); // ticket #3303
TEST_CASE(class24); // ticket #3806 - false positive in copy constructor
TEST_CASE(class25); // ticket #4367 - false positive implementation for destructor is not seen
TEST_CASE(class26); // ticket #10789
TEST_CASE(staticvar);
@ -1450,6 +1451,17 @@ private:
ASSERT_EQUALS("", errout.str());
}
void class26() { // ticket #10789 - crash
check("class C;\n"
"struct S {\n"
" S() { p = new C; }\n"
" ~S();\n"
" C* p;\n"
"};\n"
"S::~S() = default;\n");
ASSERT_EQUALS("[test.cpp:5]: (style) Class 'S' is unsafe, 'S::p' can leak by wrong usage.\n", errout.str());
}
void staticvar() {
check("class A\n"
"{\n"