diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 3f2a887fd..1887a0e83 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -749,7 +749,7 @@ void CheckMemoryLeakStructMember::check() { const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase(); for (const Variable* var : symbolDatabase->variableList()) { - if (!var || !var->isLocal() || var->isStatic()) + if (!var || !var->isLocal() || var->isStatic() || var->isReference()) continue; if (var->typeEndToken()->isStandardType()) continue; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 8d7f29543..9fb70dca0 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -4769,6 +4769,9 @@ private: // local struct variable TEST_CASE(localvars); + // struct variable is a reference variable + TEST_CASE(refvar); + // Segmentation fault in CheckMemoryLeakStructMember TEST_CASE(trac5030); @@ -5104,6 +5107,20 @@ private: ASSERT_EQUALS("", errout.str()); } + void refvar() { // #8116 + check("struct Test\n" + "{\n" + " int* data;\n" + "};\n" + "\n" + "void foo(Test* x)\n" + "{\n" + " Test& y = *x;\n" + " y.data = malloc(10);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + // don't crash void trac5030() { check("bool bob( char const **column_ptrs ) {\n"