Fixed #2981 (False positive: struct member leak)
This commit is contained in:
parent
8a6a999f09
commit
2150995475
|
@ -3161,6 +3161,12 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Token * const vartok
|
|||
break;
|
||||
}
|
||||
|
||||
// struct assignment..
|
||||
else if (Token::Match(tok3, "= %varid% ;", structid))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// goto isn't handled well.. bail out even though there might be leaks
|
||||
else if (tok3->str() == "goto")
|
||||
break;
|
||||
|
|
|
@ -4962,6 +4962,7 @@ private:
|
|||
// assignments
|
||||
TEST_CASE(assign1);
|
||||
TEST_CASE(assign2);
|
||||
TEST_CASE(assign3);
|
||||
|
||||
// Failed allocation
|
||||
TEST_CASE(failedAllocation);
|
||||
|
@ -5100,11 +5101,21 @@ private:
|
|||
{
|
||||
check("static void foo() {\n"
|
||||
" struct ABC *abc = malloc(123);\n"
|
||||
" abc->a = abc->b = malloc(10)\n"
|
||||
" abc->a = abc->b = malloc(10);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void assign3()
|
||||
{
|
||||
check("void f(struct s *f1) {\n"
|
||||
" struct s f2;\n"
|
||||
" f2.a = malloc(100);\n"
|
||||
" *f1 = f2;\n"
|
||||
"}\n", "test.c");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void failedAllocation()
|
||||
{
|
||||
check("static struct ABC * foo()\n"
|
||||
|
|
Loading…
Reference in New Issue