Fixed #8116 ([False positive] Invalid memory leak detection when using reference.)

This commit is contained in:
Daniel Marjamäki 2019-01-09 20:38:32 +01:00
parent 75e367c48b
commit 35e56942d1
2 changed files with 18 additions and 1 deletions

View File

@ -749,7 +749,7 @@ void CheckMemoryLeakStructMember::check()
{ {
const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase(); const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Variable* var : symbolDatabase->variableList()) { for (const Variable* var : symbolDatabase->variableList()) {
if (!var || !var->isLocal() || var->isStatic()) if (!var || !var->isLocal() || var->isStatic() || var->isReference())
continue; continue;
if (var->typeEndToken()->isStandardType()) if (var->typeEndToken()->isStandardType())
continue; continue;

View File

@ -4769,6 +4769,9 @@ private:
// local struct variable // local struct variable
TEST_CASE(localvars); TEST_CASE(localvars);
// struct variable is a reference variable
TEST_CASE(refvar);
// Segmentation fault in CheckMemoryLeakStructMember // Segmentation fault in CheckMemoryLeakStructMember
TEST_CASE(trac5030); TEST_CASE(trac5030);
@ -5104,6 +5107,20 @@ private:
ASSERT_EQUALS("", errout.str()); 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 // don't crash
void trac5030() { void trac5030() {
check("bool bob( char const **column_ptrs ) {\n" check("bool bob( char const **column_ptrs ) {\n"