diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 5a20fa2a4..c38c9da69 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -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()) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 9c190ff67..a35db582d 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -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"