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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct assignment..
|
||||||
|
else if (Token::Match(tok3, "= %varid% ;", structid))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// goto isn't handled well.. bail out even though there might be leaks
|
// goto isn't handled well.. bail out even though there might be leaks
|
||||||
else if (tok3->str() == "goto")
|
else if (tok3->str() == "goto")
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -4962,6 +4962,7 @@ private:
|
||||||
// assignments
|
// assignments
|
||||||
TEST_CASE(assign1);
|
TEST_CASE(assign1);
|
||||||
TEST_CASE(assign2);
|
TEST_CASE(assign2);
|
||||||
|
TEST_CASE(assign3);
|
||||||
|
|
||||||
// Failed allocation
|
// Failed allocation
|
||||||
TEST_CASE(failedAllocation);
|
TEST_CASE(failedAllocation);
|
||||||
|
@ -5100,11 +5101,21 @@ private:
|
||||||
{
|
{
|
||||||
check("static void foo() {\n"
|
check("static void foo() {\n"
|
||||||
" struct ABC *abc = malloc(123);\n"
|
" struct ABC *abc = malloc(123);\n"
|
||||||
" abc->a = abc->b = malloc(10)\n"
|
" abc->a = abc->b = malloc(10);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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()
|
void failedAllocation()
|
||||||
{
|
{
|
||||||
check("static struct ABC * foo()\n"
|
check("static struct ABC * foo()\n"
|
||||||
|
|
Loading…
Reference in New Issue