Fixed #2503 (false positive: memory leak (struct member, address is taken))
This commit is contained in:
parent
f87056fca3
commit
dbc5929fa2
|
@ -2999,7 +2999,7 @@ void CheckMemoryLeakStructMember::check()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Struct member is allocated => check if it is also properly deallocated..
|
// Struct member is allocated => check if it is also properly deallocated..
|
||||||
else if (Token::Match(tok2, "%varid% . %var% = malloc|strdup|kmalloc (", vartok->varId()))
|
else if (Token::Match(tok2->previous(), "[;{}] %varid% . %var% = malloc|strdup|kmalloc (", vartok->varId()))
|
||||||
{
|
{
|
||||||
const unsigned int structid(vartok->varId());
|
const unsigned int structid(vartok->varId());
|
||||||
const unsigned int structmemberid(tok2->tokAt(2)->varId());
|
const unsigned int structmemberid(tok2->tokAt(2)->varId());
|
||||||
|
|
|
@ -4253,7 +4253,8 @@ private:
|
||||||
TEST_CASE(ret2);
|
TEST_CASE(ret2);
|
||||||
|
|
||||||
// assignments
|
// assignments
|
||||||
TEST_CASE(assign);
|
TEST_CASE(assign1);
|
||||||
|
TEST_CASE(assign2);
|
||||||
|
|
||||||
// Failed allocation
|
// Failed allocation
|
||||||
TEST_CASE(failedAllocation);
|
TEST_CASE(failedAllocation);
|
||||||
|
@ -4356,7 +4357,7 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void assign()
|
void assign1()
|
||||||
{
|
{
|
||||||
check("static void foo()\n"
|
check("static void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -4385,6 +4386,15 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void assign2()
|
||||||
|
{
|
||||||
|
check("static void foo() {\n"
|
||||||
|
" struct ABC *abc = malloc(123);\n"
|
||||||
|
" abc->a = abc->b = malloc(10)\n"
|
||||||
|
"}\n");
|
||||||
|
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