Merge pull request #2702 from rikardfalkeborn/9793-false-positive-lambda
Fix #9793 (false positive, memleak with lambda)
This commit is contained in:
commit
e26f717f59
|
@ -764,6 +764,8 @@ void CheckMemoryLeakStructMember::check()
|
|||
continue;
|
||||
if (var->typeEndToken()->isStandardType())
|
||||
continue;
|
||||
if (var->scope()->hasInlineOrLambdaFunction())
|
||||
continue;
|
||||
checkStructVariable(var);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4447,6 +4447,8 @@ bool Scope::hasInlineOrLambdaFunction() const
|
|||
// Lambda function
|
||||
if (s->type == Scope::eLambda)
|
||||
return true;
|
||||
if (s->hasInlineOrLambdaFunction())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1677,6 +1677,8 @@ private:
|
|||
TEST_CASE(varid_2); // #5315: Analysis confused by ((variable).attribute) notation
|
||||
|
||||
TEST_CASE(customAllocation);
|
||||
|
||||
TEST_CASE(lambdaInForLoop); // #9793
|
||||
}
|
||||
|
||||
void err() {
|
||||
|
@ -2062,6 +2064,22 @@ private:
|
|||
"}", false);
|
||||
ASSERT_EQUALS("[test.c:7]: (error) Memory leak: abc.a\n", errout.str());
|
||||
}
|
||||
|
||||
void lambdaInForLoop() { // #9793
|
||||
check(
|
||||
"struct S { int * p{nullptr}; };\n"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" S s;\n"
|
||||
" s.p = new int[10];\n"
|
||||
" for (int i = 0; i < 10; ++i) {\n"
|
||||
" s.p[i] = []() { return 1; }();\n"
|
||||
" }\n"
|
||||
" delete[] s.p;\n"
|
||||
" return 0;\n"
|
||||
"}", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestMemleakStructMember)
|
||||
|
|
Loading…
Reference in New Issue